הערה
הגישה לדף זה מחייבת הרשאה. באפשרותך לנסות להיכנס או לשנות מדריכי כתובות.
הגישה לדף זה מחייבת הרשאה. באפשרותך לנסות לשנות מדריכי כתובות.
Question
Friday, May 24, 2013 6:48 AM
I want to get the index of selected items from a list view. I am using this code
Dim txtCount As Integer
txtCount = listview1.FocusedItem.Index
but focusedItem returns the index of last selected item..its not precise at the runtime
can anyone give me the other way round.....
rootkit123
All replies (8)
Friday, May 24, 2013 8:21 AM ✅Answered
You can try the code below. SelectedIndices will give you SelectedIndexCollection. 0 is the item that is selected first.
listView.SelectedIndices(0)
Friday, May 24, 2013 6:56 AM
Try using the mouseup and keyup events
I'm new to .Net, OOP and this forum but love it!
Friday, May 24, 2013 6:59 AM
And use the same code i gave you in your last question
I'm new to .Net, OOP and this forum but love it!
Friday, May 24, 2013 8:52 AM
I assume you want not the selecteditems index (those go from 0 to the last), but the position inside the listview of those selected items.
That is afaik completely depending from the sort position at that moment of the listview.
In fact impossible.
Success
Cor
Friday, May 24, 2013 10:24 AM
are you looking for some sort of array of values representing the index values of each item in the selected range?
I'm new to .Net, OOP and this forum but love it!
Friday, May 24, 2013 11:33 AM
If you want the first or only selected index of a listview item then try the code in Button1 and if you want a collection of selected indexes then try the code in Button2.
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
If ListView1.SelectedItems.Count > 0 Then
Dim txtcount As Integer = ListView1.SelectedIndices(0) 'Gets the index of the first selected index
MessageBox.Show(txtcount.ToString)
End If
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
If ListView1.SelectedItems.Count > 0 Then
Dim txtcount = ListView1.SelectedIndices 'Gets a collection of selected indexes
For Each indx As Integer In txtcount
MessageBox.Show(indx.ToString)
Next
End If
End Sub
Friday, May 24, 2013 2:51 PM
thnx...it worked
rootkit123
Friday, May 24, 2013 5:24 PM
yes i do
rootkit123