[英]Accessing Selected Index of ListBox
I'm attempting to access a list called people and I'm matching up the index of the listitem selected to the index of my list so that I can print the surname of the person to a textbox. 我正在尝试访问一个名为people的列表,并且正在将所选列表项的索引与列表的索引进行匹配,以便可以将该人的姓氏打印到文本框中。 I have this code:
我有以下代码:
surnameTxtBox.Text = people[listBoxNames.SelectedItems[0].Index].Surname;
listBoxNames is the name of my ListBox but for some reason, visual studio tells me that there's no definition called index? listBoxNames是我的ListBox的名称,但是由于某种原因,Visual Studio告诉我没有所谓的索引定义?
您需要SelectedIndex
来获取SelectedItem索引:
surnameTxtBox.Text = people[listBoxNames.SelectedIndex].Surname;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.