Easy way to find a win control in next tab order

D

David Kao

HI All:

I am currently implementing a TextBox to allow user to type the
things the user wants to search. The actual search routine is
happening on Textbox Validated event. My user wants me trap enter
key in the Search TextBox, so that after the user complete their
search string. The user can either press enter key or shift the
focus to next control. The problem I am facing I cannot easily find
out what is my next tab control on my win form. I have to write
small routine to search for. I just want to know is there anyone in
this newsgroup has better solution.
....
private void textBox1_KeyPress(object
sender,System.Windows.Forms.KeyPressEventArgs e) {
if (e.KeyChar == '\r')
{
Control ctr = FindNextTabControl
(this.textBox1.TabIndex + 1);
ctr.Focus(); // to triggle validated event to
perform the search
}
}

private Control FindNextTabControl(int TabIndex)
{
Control retCtr = null;
foreach(Control ctr in this.Controls)
{
if (ctr.TabIndex == TabIndex)
{
retCtr = ctr;
break;
}
else if (ctr.TabIndex == 0)
retCtr = ctr;
}
return retCtr;
}

private void textBox1_Validated(object sender,
System.EventArgs e)
{
//actual search here
}
....

Thanks in Advance
DK
 
G

Guest

I don't follow what you're trying to do. If the user presses <Enter> while
in the text box then you trap that keystroke and do a search, right? From
that same text box, can't the user simply press <tab> to go to the next
control in tab order? Or am I missing something?

..ARN.
 

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