ListView Control - ItemActivate event

mjohnson3091

Freshman
Joined
Aug 10, 2004
Messages
31
Location
Lancashire, UK
Hi,

I'm writing some code in c# for a mobile device.

I have a list view that raises the ItemActivate event on a double click or by the user selecting an item using the cursor keys and pressing Enter.

This may be a silly question, but how can I determine whether it was the double click or the Enter/Return key pressed that raises the event?

Thanks in advance.

Mark
 
Add a "KeyDown" event handler for your ListView control.

This is by no means complete:
Code:
bool _usedEnter = false;
void p5_Why_KeyDown(object sender, KeyEventArgs e) {
  _usedEnter = false;
  if (e.KeyCode == Keys.Enter) {
    _usedEnter = true;
    // Enter Key was pressed.
  }
}
Basically, set an boolean value that you can then check in the ItemActivate event that you already have.

Hope that helps!
 
It seems to me that the ItemActivate event is specifically intended to be input-method agnostic. If you need to differentiate, you can use the DoubleClick and KeyPress events (KeyDown won't catch the keyboard repeat), and forget about the ItemActivate event.

Note that these events appear to be triggered after the ItemActivate, but there is no good reason to make any assumption about the order the events will fire in. It might vary between OSes or WinForm versions.
 
Back
Top