簡體   English   中英

訪問列表框的選定索引

[英]Accessing Selected Index of ListBox

我正在嘗試訪問一個名為people的列表,並且正在將所選列表項的索引與列表的索引進行匹配,以便可以將該人的姓氏打印到文本框中。 我有以下代碼:

surnameTxtBox.Text = people[listBoxNames.SelectedItems[0].Index].Surname;

listBoxNames是我的ListBox的名稱,但是由於某種原因,Visual Studio告訴我沒有所謂的索引定義?

您需要SelectedIndex來獲取SelectedItem索引:

surnameTxtBox.Text = people[listBoxNames.SelectedIndex].Surname;

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM