获取ListBox C++的所选项目ID
Get Selected Item ID of ListBox C++
我试图制作一个简单的程序,在ListBox中列出几个名称,当选择其中一个时,单击一个按钮应该会在几个TextBox中加载数据。。。我只需要列表框中所选项目的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中只列出了其中一个。有人能帮忙吗?提前感谢:-)
我自己找到了答案:)
以下是我搜索的内容,如果有人来此帖子:
int i = this->listBox1->SelectedIndex;
相关文章:
- 如何在选项卡视图Qt中设置一个新项目,并保存以前的项目
- C++项目编译强制使用 /clr 选项,尽管在没有公共语言运行时支持的情况下执行它
- 暂时将C++项目(VS2015)移至Android操作系统.编译器选项?
- 是否有任何 MSBuild 命令行选项可以动态禁用 c++ 项目的代码分析?
- 用于在 Visual Studio 中为整个项目或解决方案定义带有参数的预处理器宏的选项
- 如何将cacert.pem与vs2015 curl项目一起包含,因此无需指定Cainfo curl选项
- Visual Lint?中的每个项目选项
- C++:使用 g++ 和 -m32 选项构建的 c++ 库在 Msys 下构建 wxWidgets 项目时出现 ld 不
- 如何在 eclipse makefile 项目中的编译器选项中设置 -std=c++0x
- 无法使项目,无法识别的命令行选项libc ++错误
- 将cmake构建选项导出到外部项目
- 为什么c++透视图和新项目选项在Eclipse中不可用
- 4.9.9.2项目选项不工作
- 无法使用/ CLR选项从Visual c++项目加载CLR
- 如何将code::块设置为在目标链接器选项之前链接项目链接器选项
- 可以qmake-configure Visual Studio项目中的命令行选项
- 在我的项目中使用预编译的头(clang/llvm,但也使用gcc).如何在make中部署-include选项
- 从下拉框中选择其他项目时更改选项卡小部件的 currentIndex()
- 使用 /Command 选项从命令行为 Visual Studio C++ 项目创建一个新文件
- 向Eclipse CDT Autotools项目添加链接器选项