SelectedIndices

V

Venue

In a listView when I select an items the first time it returns me the
correct value of the currently selected rows. (using
listView.SelectedIndices[0] ).

Second subsequent call results into an excception "index". But when I click
OK it gives the correct value. But the third time again it throws an
exception "index" and on clicking OK the application dies down.

What am I doing wrong.
 
P

Peter Foot [MVP]

What type of exception is raised (ArgumentOutOfRangeException ?)
Are you checking the size of SelectedIndices before querying the first
value - if SelectedIndices is null or of Zero length a call to
SelectedIndices[0] won't work

Peter
 
V

Venue

I check the value of SelectedIndices and it is not zero or null, it works
and gives the correct value of index when I click OK after it throws an
exception, second time around. It thows a
{System.ArgumentOutOfRangeException} and the Exception.Message is "index".



Peter Foot said:
What type of exception is raised (ArgumentOutOfRangeException ?)
Are you checking the size of SelectedIndices before querying the first
value - if SelectedIndices is null or of Zero length a call to
SelectedIndices[0] won't work

Peter

--
Peter Foot
Windows Embedded MVP
OpenNETCF.org Senior Advisor
www.inthehand.com | www.opennetcf.org

Venue said:
In a listView when I select an items the first time it returns me the
correct value of the currently selected rows. (using
listView.SelectedIndices[0] ).

Second subsequent call results into an excception "index". But when I click
OK it gives the correct value. But the third time again it throws an
exception "index" and on clicking OK the application dies down.

What am I doing wrong.
 
V

Venue

Found the problem, as Peter suggested I need to check the count of
selectedIndices I guess and it goes fine.

thanks,


Venue said:
I check the value of SelectedIndices and it is not zero or null, it works
and gives the correct value of index when I click OK after it throws an
exception, second time around. It thows a
{System.ArgumentOutOfRangeException} and the Exception.Message is "index".



Peter Foot said:
What type of exception is raised (ArgumentOutOfRangeException ?)
Are you checking the size of SelectedIndices before querying the first
value - if SelectedIndices is null or of Zero length a call to
SelectedIndices[0] won't work

Peter

--
Peter Foot
Windows Embedded MVP
OpenNETCF.org Senior Advisor
www.inthehand.com | www.opennetcf.org

Venue said:
In a listView when I select an items the first time it returns me the
correct value of the currently selected rows. (using
listView.SelectedIndices[0] ).

Second subsequent call results into an excception "index". But when I click
OK it gives the correct value. But the third time again it throws an
exception "index" and on clicking OK the application dies down.

What am I doing wrong.
 

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