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. 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?
您需要SelectedIndex
来获取SelectedItem索引:
surnameTxtBox.Text = people[listBoxNames.SelectedIndex].Surname;
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.