[RESOLVED] [2005] Listview SelectedIndexes
In my listview this are the values.
1 - Dog - 19
2 - Cat - 2
3 - Shrew - 5
How to retrieve the selectedindex in the listview ? If i select the first record the index must be "0" if the second record then the index is "1" if the third the index is "2". i use this method but it gives me a wrong output.
Code:
Me.Text = Listview1.SelectedIndexes.ToString
The output of that is System.Windows.Form.Listview......
Re: [2005] Listview SelectedIndexes
Shouldn't
Me.Text be something like Me.ControlType.text?
Re: [2005] Listview SelectedIndexes
Whether i print it on a textbox, other control and a msgbox ... the output is the same
Re: [2005] Listview SelectedIndexes
Code:
txtemailAddress.Text = Me.lsvContacts.SelectedItems(0).SubItems(1).Text
HTH
Re: [2005] Listview SelectedIndexes
but it only retrieve the first record. How about the others ?
Re: [2005] Listview SelectedIndexes
Change this SubItems(1) to this SubItems(2), i hope :)
Re: [2005] Listview SelectedIndexes
I use the ListView_SelectedItemChange So how im gonna use the indexes.
If i use that on a Click event my code and your code would work. But How about on a SelectedItemChanged event ?
Re: [2005] Listview SelectedIndexes
Try this:
VB.NET Code:
Dim index As Integer
index = Me.ListView1.FocusedItem.Index
Re: [2005] Listview SelectedIndexes
this will show a messagebox for each selected item in the listview!
vb Code:
Dim indexes As ListView.SelectedIndexCollection = ListView1.SelectedIndices
Dim index, i As Integer
For Each index In indexes
msgbox(ListView1.Items(index).SubItems(1).Text)
Next
Re: [2005] Listview SelectedIndexes
Thanks toecutter and D4rkness. Now i know the function of the FocusedItem method of a listview thanks again :)
Re: [2005] Listview SelectedIndexes
Thanks stef-o that was amzing you gave me how to use the selectedindeces im so happy thanks all of you.
Re: [RESOLVED] [2005] Listview SelectedIndexes
No Problem, glad to help. :)