|
web
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
Listview - get value multiple columnsDoes anyone know how to get a value of a second column of a selected item in Listview. I've create a listview and added this code Listview.Items.Clear() Listview.Columns.Clear() Listview.View = View.Details Listview.Columns.Add("ID", 0, HorizontalAlignment.Left) Listview.Columns.Add("Toppic", 150, HorizontalAlignment.Left) Listview.Columns.Add("Name", 150, HorizontalAlignment.Left) Listview.FullRowSelect = True I can retreive the data from the first column, i've selected... myString = Listview.SelectedItems.Item(0) ... but I can't get any data out of the next columns i've selected... myString2 = Listview.SelectedItems.Item(1) myString3 = Listview.SelectedItems.Item(2) .... this doesn' work ... Does anyone have any idea's Thanx John
Show quote
Hide quote
"John Devlon" <johndev***@hotmail.com> wrote in message news:E5BIg.45995$Dj3.318499@phobos.telenet-ops.be... Look at the SibItems collection.> Hi, > > Does anyone know how to get a value of a second column of a selected item > in Listview. > > I've create a listview and added this code > > Listview.Items.Clear() > Listview.Columns.Clear() > Listview.View = View.Details > > Listview.Columns.Add("ID", 0, HorizontalAlignment.Left) > Listview.Columns.Add("Toppic", 150, HorizontalAlignment.Left) > Listview.Columns.Add("Name", 150, HorizontalAlignment.Left) > Listview.FullRowSelect = True > > I can retreive the data from the first column, i've selected... > > myString = Listview.SelectedItems.Item(0) > > .. but I can't get any data out of the next columns i've selected... > > myString2 = Listview.SelectedItems.Item(1) > myString3 = Listview.SelectedItems.Item(2) > > ... this doesn' work ... > > Does anyone have any idea's > > Thanx > > John > > myString2 = Listview.SelectedItems.Item(0).SubItems(1).Text -- Al Reid Many thanks for your help ...
At first it worked great When using it like this .. Private Sub Listview_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Listview.SelectedIndexChanged txtName.Text = Listview.SelectedItems.Item(0).SubItems(1).Text End Sub Strange problems occure ... The first time I select something, it works fine.. the data from the listview go's into the textfield. When i select something else, I get a ArgumentOutOfRangeException ... Any idea's? john If there are no selected items you will get this error. Check the SelectedItems.Count Property.
See inline. "John Devlon" <johndev***@hotmail.com> wrote in message news:xLBIg.46054$Oy3.583802@phobos.telenet-ops.be... If Listview.SelectedItems.Coun > 0 Then> Many thanks for your help ... > > At first it worked great > > When using it like this .. > > Private Sub Listview_SelectedIndexChanged(ByVal sender As System.Object, > ByVal e As System.EventArgs) Handles Listview.SelectedIndexChanged > txtName.Text = Listview.SelectedItems.Item(0).SubItems(1).Text EndifShow quoteHide quote > End Sub > > Strange problems occure ... > > The first time I select something, it works fine.. the data from the > listview go's into the textfield. > When i select something else, I get a ArgumentOutOfRangeException ... > > Any idea's? > > john > > -- Al Reid Hi,
I've tested the application using your code and I found the problem ... When selecting something else in a Listview, the methode that handles the SelectedIndexChanged is triggerd twice.... First, it sets the selectedItems to 0, then to 1, represting the new selected value ... Strang, but the problem is solved .. Many, Many thanx.... Show quoteHide quote > If there are no selected items you will get this error. Check the > SelectedItems.Count Property.
Show quote
Hide quote
"John Devlon" <johndev***@hotmail.com> wrote in message Not that strange. This is by design. When you select an item in a ListView news:09DIg.46163$dQ5.673913@phobos.telenet-ops.be... > > Hi, > > I've tested the application using your code and I found the problem ... > > When selecting something else in a Listview, the methode that handles the > SelectedIndexChanged > is triggerd twice.... > > First, it sets the selectedItems to 0, then to 1, represting the new > selected value ... > > Strang, but the problem is solved .. it first deselects the previously selected item and this triggers the first SelectedIndexChanged (were count = 0). Then it selects the item you clicked on and this triggers the second SelectedIndexChanged (were count = 1). Hence the check on count is necessary. /claes |
|||||||||||||||||||||||