我试图制作一个简单的程序,在ListBox中列出几个名字,当选择其中一个,并点击一个按钮时,应该在少量TextBox中加载数据...我需要的只是所选的ID该ListBox的项目,因为数据在数组中,我无法获得没有该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
}
P.S。我想以这种方式做到这一点,因为数组有类,我在一个ID中放了多个项目,但在ListBox中只列出其中一个。 有人可以帮忙吗?在此先感谢: - )
答案 0 :(得分:0)
我自己找到了答案:)
以下是我搜索的内容,如果有人来这篇文章:
int i = this->listBox1->SelectedIndex;