i have a listview with the following columns id, surname, firstname. i want to get the surname when a row is selected how do i do it using visual c开发者_开发问答# 2008?
subscribing SelectedIndexChanged for ListView1:
ListView1.SelectedItems[0].Subitems[1].Text
you have some tons of microsoft documentation about it..
http://msdn.microsoft.com/en-us/library/system.windows.forms.listviewitem.listviewsubitem.aspx
You have to obtain the selected Item: SelectedItem
, then look in the SubItems collection. In general we can say that is better to have some object bound to the item ( for example in the tag ) and obtain back th einformation from it.
Create a SelectedIndexChanged
Event or ItemActivate
(if you want to double click the item before it fires whatever work you want).
listView1.SelectedItems[0].Subitems[1].Text
Remember that SubItems
start at zero index and in your surname column is in index of 1. Column id takes the zero index.
精彩评论