0

Hi,

I have one form, in that one textbox & Buttons is there for Search functionality. Enter whatever in the text box, it will search from the one of the Tree View Node.

So my question is when I form is showed to user and when I press the Enter Key, it will serach the that Text in from the Tree node rather then click on that Search button ?

5
Contributors
4
Replies
16
Views
4 Years
Discussion Span
Last Post by Momerath
0

Every control including the form has they're own KeyPress event, which makes programming for that quite a bother. A more efficient solution would be to give the textbox first tabindex, so that when the form starts the textbox immediatley has focus. This way you only need to program the KeyPress event handler for one control

1

You need to have a method in the KeyDown event of the textbox like say :-

private void CallKeyDown(object sender, KeyEventArgs e)
{
    if(e.Key==Key.Return)
    {
      // Your Search Functionality
    }
}

Hope that helps :)

Edited by KM499: Code added

0

If you set the KeyPreview property of the Form to true, it will get to see if it wants to handle the keypress before it's passed on to whatever control has focus, so you don't need a handler for all the controls, just one for the form.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.