I and the listview again

  • Thread starter Thread starter Daniel Sélen Secches
  • Start date Start date
D

Daniel Sélen Secches

Hi all....

I've a listview whit 6 items and 3 columns just for a exemple, and I've
tryed to do this...

;;;;;
Private Sub listview1_SelectedIndexChanged(ByVal sender As Object, ByVal
e As System.EventArgs) Handles listview1.SelectedIndexChanged
MsgBox(listview1.SelectedItems.Item(0).Index.ToString)
End Sub
;;;;;;;;;;

when the event is triggered for the first time it works just fine, but on
the second time:

;;;;;;
An unhandled exception of type 'System.ArgumentOutOfRangeException' occurred
in system.windows.forms.dll
Additional information: Specified argument was out of the range of valid
values.
;;;;;;;;

if i put this code for a click event of the listview it always works


--
tks.

Daniel Sélen Secches
CWD Web Internet.
www.cwd.com.br
 
Daniel,

I'm not sure of the inner workings, but it appears that the
SelectedIndexChanged event is fired first as you move off an item and then
again as you move onto another item. If its a single select listview, or
only one item is selected, as you move off the item, SelectedItem(0) will be
Nothing, and so an exception is thrown. You can enclose it in a Try/Catch
block

Try
MsgBox(listview1.SelectedItems.Item(0).Index.ToString)
Catch e as ArgumentOutOfRangeException
'Do nothing
End Try

Stephen
 
tks... it's works fine...


Stephen Muecke said:
Daniel,

I'm not sure of the inner workings, but it appears that the
SelectedIndexChanged event is fired first as you move off an item and then
again as you move onto another item. If its a single select listview, or
only one item is selected, as you move off the item, SelectedItem(0) will be
Nothing, and so an exception is thrown. You can enclose it in a Try/Catch
block

Try
MsgBox(listview1.SelectedItems.Item(0).Index.ToString)
Catch e as ArgumentOutOfRangeException
'Do nothing
End Try

Stephen
 
Back
Top