获取ListBox C++的选定项ID

Get Selected Item ID of ListBox C++

我试图制作一个简单的程序,在列表框中列出了几个名称,然后选择其中一个名称,然后单击一个按钮应将数据加载到几个文本框中...我只需要该 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。我想这样做,因为数组有 class 并且我在一个 ID 中放置了多个项目,但在 ListBox 中只列出了其中一个。 有人可以帮忙吗?提前致谢:-)

我自己找到了答案:)

这是我搜索的内容,如果有人来这里 post:

int i = this->listBox1->SelectedIndex;