Listview Item Click will not be fired

  • Thread starter Thread starter =?iso-8859-1?B?Qmr2cm4=?=
  • Start date Start date
?

=?iso-8859-1?B?Qmr2cm4=?=

Hallo together,

I use the Listview in .NET CF under Visual Studio .NET 2003.
I am adding the LV Items like this at the runtime:


locLVItem = New ListViewItem
locLVItem.Text = "XYZ"
locLVItem.SubItems.Add("XY")
PubFrmMain.LView.Items.Add(locLVItem)
The problem is that the Listview provides an Click Event but it will never be started. Is the Click Event not usable in .NET CF?

The SelectedIndexChanged Event I cannot use because the event will be fired before the Item is focused and so I cannot find the Focused item in this event:

If CType(sender, ListView).Focused = True Then

PubLVClickIndex = CType(sender, ListView).FocusedItem.Index

End If



Can anybody help me?

Greetings BG
 
Hi, BG

The click event isn't supported by some of the controls
in the .NET CF. Instead, use the SelectedIndexChanged
event and search the ListView.SelectedIndexCollection to
find the selected item(s).

Hope that helps =)

Flynn
-----Original Message-----
Hallo together,

I use the Listview in .NET CF under Visual Studio .NET 2003.
I am adding the LV Items like this at the runtime:


locLVItem = New ListViewItem
locLVItem.Text = "XYZ"
locLVItem.SubItems.Add("XY")
PubFrmMain.LView.Items.Add(locLVItem)
The problem is that the Listview provides an Click Event
but it will never be started. Is the Click Event not
usable in .NET CF?
The SelectedIndexChanged Event I cannot use because the
event will be fired before the Item is focused and so I
cannot find the Focused item in this event:
 
The problem with the SelectedIndexChanged event is that it doesn't fire if
the user clicks an item that is already selected. If anyone knows how to get
a click event to work in ListView or TreeView, please post here. Thanks.
 
A correction to the McSoft package I referenced - it doesn't add a Click
event to the controls, it adds MouseDown, MouseUp, and DoubleClick
events (among other things).

Flynn
 
You're correct that the ListView control shows a Click event in
Intellisense. However, as you also pointed out, that Click event never
gets fired. The SelectedIndexChanged event works well for most things.

If you just want the index of the item that's focused, try this:

Dim item As ListViewItem
For Each item In lstView.Items
If item.Selected = True Then
PubLvClickIndex = item.Index
Exit For
End If
Next

You would fire this routine inside the SelectedIndexChanged event.

You could also extend the control yourself to add a Click event,
however, I'm not certain how to do that.

If all else fails, there is a package available for .NET CF developers
that adds the Click event to the CF controls. The package is available
from http://www.mcsoft.com.au/. I don't know how much the package costs,
but there is a demo version availbale.

Flynn
 
Back
Top