mjohnson3091 Posted March 24, 2009 Posted March 24, 2009 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 Quote
joe_pool_is Posted April 16, 2009 Posted April 16, 2009 Add a "KeyDown" event handler for your ListView control. This is by no means complete: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! Quote Avoid Sears Home Improvement
Leaders snarfblam Posted April 16, 2009 Leaders Posted April 16, 2009 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. Quote [sIGPIC]e[/sIGPIC]
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.