How to get the selected index of a ListView item ?
-
Hi, we use a ListView control in order to show thumbnails. After we add some thumbnails, we need to know which thumbnail(ListViewItem is selected or clicked/selected with the mouse) and for this we use ListView1_SelectedIndexChanged event. To know that, we want to know the slected index of the ListView so we use the .SelectedIndices(0) method, but it gets an exception error as shown below. Private Sub ListView1_SelectedIndexChanged(ByVal .....) Dim index as Integer index = ListView1.SelectedIndices(0) End Sub - ex {"InvalidArgument=Value of '0' is not valid for 'index'. Parameter name: index"} System.Exception Any idea how to retrieve the index of the selected ListViewItem?
-
Hi, we use a ListView control in order to show thumbnails. After we add some thumbnails, we need to know which thumbnail(ListViewItem is selected or clicked/selected with the mouse) and for this we use ListView1_SelectedIndexChanged event. To know that, we want to know the slected index of the ListView so we use the .SelectedIndices(0) method, but it gets an exception error as shown below. Private Sub ListView1_SelectedIndexChanged(ByVal .....) Dim index as Integer index = ListView1.SelectedIndices(0) End Sub - ex {"InvalidArgument=Value of '0' is not valid for 'index'. Parameter name: index"} System.Exception Any idea how to retrieve the index of the selected ListViewItem?
You first have to check if
SelectedIndices
contains anything at all. TheSelectedIndexChanged
event is also triggered when the previously selected item is unselected, and then no item is selected and the collection is empty.--- single minded; short sighted; long gone;