ListView events

G

Guest

Hi, All
I have ListView1 populated with one column (.NET 2003 version 1.1, SP3)
I need to populate second ListView2 with a few columns when user selects row
from ListView1.
I tried to extract the value of the selected row in
ListView_SelectedIndexChanged() event and ListView_ItemActivate(), but seems
it doesn't work.
What event fires when row selected in the ListView? Or how can i activate
event?
Please, advice
Thank you
 
P

Peter Foot [MVP]

You'll have to show us your code to show what "doesn't work".
SelectedIndexChanged occurs whenever the user selects a different item in
the list or removes a selection - you must check the SelectedIndices
property to make sure a selection was made. ItemActivate occurs when the
user first selects an item. If you tap an already selected item it won't
raise another event.

Peter
 
G

Guest

Hi, Peter
the following code doesn't work:

Private Sub ListView1_ItemActivate(ByVal sender As Object, ByVal e As
System.EventArgs) Handles ListView1.ItemActivate
MsgBox(ListView1.FocusedItem.Text)
End Sub

This one display message:

Private Sub ListView1_SelectedIndexChanged(ByVal sender As Object, ByVal e
As System.EventArgs) Handles ListView1.SelectedIndexChanged
Dim item As ListViewItem

For Each item In ListView1.Items
If item.Selected = True Then
ClickIndex = item.Index
MsgBox(ClickIndex.ToString)
Exit For
End If
Next
End Sub

Please, advice
Thank you
 
P

Peter Foot [MVP]

You don't need to loop through the collection to find the selected items -
use the SelectedIndices property. e.g.

If ListView1.SelectedIndices.Length > 0 Then
MessageBox.Show(ListView1.SelectedIndices(0).ToString)
End If

An item may be selected but not currently have the focus (indeed the focus
may be on another control).

Peter
 
G

Guest

Thank you, it helps

Peter Foot said:
You don't need to loop through the collection to find the selected items -
use the SelectedIndices property. e.g.

If ListView1.SelectedIndices.Length > 0 Then
MessageBox.Show(ListView1.SelectedIndices(0).ToString)
End If

An item may be selected but not currently have the focus (indeed the focus
may be on another control).

Peter

--
Peter Foot
Microsoft Device Application Development MVP
www.peterfoot.net | www.inthehand.com
In The Hand Ltd - .NET Solutions for Mobility
 

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