I and the listview again

  • Thread starter Daniel Sélen Secches
  • 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
 
S

Stephen Muecke

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
 
D

Daniel Sélen Secches

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top