Re: How to detect which ListView item user clicks?

Tech-Archive recommends: Fix windows errors by optimizing your registry



Darren you are on!

He clicked on a listviewitem and as a result the SelectedIndexChanged event fires twice. Once with SelectedIndices.Count=0 and once with an actual item selected. Since he is not checking for that, he got the argumentexception on the line I suggested.

Robert, don't change a line in your code, stick a breakpoint on the following line and then step into once and watch the exception come up. Then point Darren to the bar :-)
index = lsvList.SelectedIndices(0)


Cheers
Daniel
--
http://www.danielmoth.com/Blog/


"Darren Shaffer" <darrenshaffer@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote in message news:%23dX5OGeQFHA.3404@xxxxxxxxxxxxxxxxxxxxxxx
Daniel - the bet is two pints at MEDC ;-)

I've gotta believe he at least clicked an item in the ListView before
he got the exception while testing, which means there is at least
one selected index and he's 'off-by-one' on his subitems index.

Robert - tt is always a good idea to do this:

if ( lvwTasks.SelectedIndices.Count > 0 )
{
    ListViewItem lvi = lvwTasks.Items[lvwTasks.SelectedIndices[0]];
//
}

before inspecting the SelectedIndices collection.

Ok Robert - there's a lot riding on your code man - what was your issue?
--
Darren Shaffer
.NET Compact Framework MVP
Principal Architect
Connected Innovation
www.connectedinnovation.com


"Daniel Moth" <dmoth74@xxxxxxxxxxx> wrote in message news:eSIwIQcQFHA.3496@xxxxxxxxxxxxxxxxxxxxxxx
>I bet the arg out of range exception is right here:
How much? :-D

I bet it is here:
index = lsvList.SelectedIndices(0)

Cheers
Daniel
--
http://www.danielmoth.com/Blog/


"Darren Shaffer" <darrenshaffer@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote in message news:u9fWdJcQFHA.2132@xxxxxxxxxxxxxxxxxxxxxxx
I bet the arg out of range exception is right here:
updQt.Value = lsvList.Items(index).SubItems(1).Text

There is probably no SubItems(1) and you should be using
SubItems(0).Text

--
Darren Shaffer
.NET Compact Framework MVP
Principal Architect
Connected Innovation
www.connectedinnovation.com

"Robert" <rxl@xxxxxxxxxxx> wrote in message news:OfW8zXYQFHA.3156@xxxxxxxxxxxxxxxxxxxxxxx

Could you be more specific?

I tried follwing code and it got an exception saying something like System.argumentsOutRange

Private Sub lsvList_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles lsvList.SelectedIndexChanged
Dim index As Integer
index = lsvList.SelectedIndices(0)
txtFMPNumber.Text = lsvList.Items(index).Text
updQt.Value = lsvList.Items(index).SubItems(1).Text
End Sub


Any ideas?



"Darren Shaffer" <darrenshaffer@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote in message news:eZe7yFVQFHA.248@xxxxxxxxxxxxxxxxxxxxxxx
you iterate the items and inspect their Checked state if using checkboxes
or inspect the SelectedIndices array if not.
--
Darren Shaffer
.NET Compact Framework MVP
Principal Architect
Connected Innovation
www.connectedinnovation.com


"Robert" <rxl@xxxxxxxxxxx> wrote in message news:uJVSU0TQFHA.3868@xxxxxxxxxxxxxxxxxxxxxxx
I can add items to the ListView but could find a way to know which row (in detail view) that the user taps.

The .NETCF does not pass current clicked index in the event procedures any more. So how do you know which row user taps?

Thanks in advance!











.



Relevant Pages

  • Re: How to detect which ListView item user clicks?
    ... > following line and then step into once and watch the exception come up. ... >> before inspecting the SelectedIndices collection. ... >> Darren Shaffer ... >>> Daniel ...
    (microsoft.public.dotnet.framework.compactframework)
  • Re: ListView events
    ... use the SelectedIndices property. ... Private Sub ListView1_ItemActivate(ByVal sender As Object, ... Dim item As ListViewItem ... Please, advice ...
    (microsoft.public.dotnet.framework.compactframework)
  • Re: ListView events
    ... You don't need to loop through the collection to find the selected items - use the SelectedIndices property. ... Private Sub ListView1_ItemActivate(ByVal sender As Object, ... Dim item As ListViewItem ... Please, advice ...
    (microsoft.public.dotnet.framework.compactframework)