【问题标题】:Get Selected Item ID of ListBox C++获取 ListBox C++ 的选定项 ID
【发布时间】:2015-03-25 21:42:45
【问题描述】:

im尝试制作一个简单的程序,列出listbox中的几个名称,并且在选择其中一个时,并且单击一个按钮应该在很少的文本框中加载数据......我所需要的只是所选的ID该列表框的项目,因为数据在数组中,如果没有该 ID,我将无法获取信息。 所以这是我的代码:

private: System::Void button1_Click(System::Object^  sender, System::EventArgs^  e) {
             this->listBox1->Items->Clear();
             if (sCount != 0) { 
                for (int i = 1; i <= sCount; i++) { 
                    String^ entry = gcnew System::String(s[i].Show().c_str()); 
                    this->listBox1->Items->Add(entry); //Listing the items from the array: s
                } 
             }
         }
private: System::Void button2_Click(System::Object^  sender, System::EventArgs^  e) {
         s[++sCount].InsertStudent("Name",270,50); //This is how i'm adding items in the array
     }
private: System::Void button3_Click(System::Object^  sender, System::EventArgs^  e) {
         int i = this->listBox1->SelectedItem; //Trying to get the ListBox Item ID
         String^ entry = gcnew System::String(s[i].Show().c_str()); //Getting the Item from the array
         this->textBox1->Text = entry; //Placing the array item into the textBox1
     }

附:我想这样做,因为数组有类,我在一个 ID 中放置了多个项目,但在 ListBox 中只列出了其中一个。 有人可以帮忙吗?在此先感谢:-)

【问题讨论】:

    标签: c++ listbox selecteditem


    【解决方案1】:

    我自己找到了答案:)

    这是我搜索的内容,如果有人来此帖子:

    int i = this->listBox1->SelectedIndex;
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-03-04
      • 2014-04-24
      • 1970-01-01
      • 2015-05-27
      • 1970-01-01
      相关资源
      最近更新 更多