PC Review


Reply
Thread Tools Rate Thread

I and the listview again

 
 
Daniel Sélen Secches
Guest
Posts: n/a
 
      3rd Mar 2004
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


 
Reply With Quote
 
 
 
 
Stephen Muecke
Guest
Posts: n/a
 
      3rd Mar 2004
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

"Daniel Sélen Secches" <danielATcwdDOTcomDOTbr> wrote in message
news:(E-Mail Removed)...
> 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
>
>



 
Reply With Quote
 
Daniel Sélen Secches
Guest
Posts: n/a
 
      4th Mar 2004
tks... it's works fine...


"Stephen Muecke" <(E-Mail Removed)> escreveu na mensagem
news:(E-Mail Removed)...
> 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
>
> "Daniel Sélen Secches" <danielATcwdDOTcomDOTbr> wrote in message
> news:(E-Mail Removed)...
> > 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
> >
> >

>
>



 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
asp.net ListView control - Configure ListView option missing? . Microsoft ASP .NET 0 24th Jul 2010 01:20 AM
Listview: When does the newvalue become currentvalue after the listview.itemcheck event? Peter Microsoft VB .NET 0 24th Feb 2005 02:00 AM
ListView.ItemCheck event fires on ListView.Items.Insert =?Utf-8?B?RGV2ZWxvcGVy?= Microsoft Dot NET Framework Forms 0 14th Sep 2004 03:21 AM
Listview Item.Selected not populating Listview.SelectedItems collection Chris Adams Microsoft Dot NET Framework Forms 0 23rd Apr 2004 01:30 AM
RE: ListView - images disappear after coming back from another form with a ListView Armin Sadeghi [MSFT] Microsoft Dot NET Compact Framework 0 5th Sep 2003 11:41 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 09:34 AM.