Im пытается сделать одну простую программу, которая перечисляет несколько имен в ListBox, и при выборе одного из них, и нажатие одной кнопки должно загружать данные в несколько текстовых полей ... Все i нужен идентификатор выбранного элемента этого списка, потому что данные находятся в массиве, и я не могу получить информацию без этого идентификатора. Так вот мой код:Получить выбранный элемент ID ListBox C++
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 указан только один из них. Может кто-нибудь помочь? Заранее спасибо :-)