Opening Dialog when user presses Enter key in List View

S

schnandr

Hi I am trying to open a Form when the user hits the Enter key in a
list view.

private void listView_KeyUp(object sender, KeyEventArgs e)
{
if (e.KeyCode == Keys.Enter)
{
OnEnterKey();
}
}

I registered a KeyUp handler. When I open the Form and I press the
Enter key in the dialog the dialog closes and the KeyUp event will be
fired again from the list view and the dialog will open again. Why
will this event will be fired when I press Enter in the dialog?

Thanks for every hint.
 
A

Armin Zingler

schnandr said:
Hi I am trying to open a Form when the user hits the Enter key in a
list view.

private void listView_KeyUp(object sender, KeyEventArgs e)
{
if (e.KeyCode == Keys.Enter)
{
OnEnterKey();
}
}

I registered a KeyUp handler. When I open the Form and I press the
Enter key in the dialog the dialog closes and the KeyUp event will
be fired again from the list view and the dialog will open again.
Why will this event will be fired when I press Enter in the dialog?

Thanks for every hint.

After you pressed the enter key down in the 2nd form, don't you release it?
;-) When you release it, the calling Form is active and receives the keyup
event. I'd catch KeyDown in the listview instead.


Armin
 

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