Click here to Skip to main content
15,887,027 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
Hi,

I have a combobox with added items, once I press the enter in the comboBox, it should go to the next tab index. I have using below code for the textBox and it's working, but for the comboBox not working, please advise.

C#
private void textBox9_KeyPress(object sender, KeyPressEventArgs e)
{
    if (e.KeyChar == (char)Keys.Enter)
    {
        SendKeys.Send("{TAB}");
    }
}
Posted
Updated 4-Aug-13 9:55am
v2

Using SendKeys of UI development is a dirty thing. All you really need it to read help with proper attention. Please see:
http://msdn.microsoft.com/en-us/library/system.windows.forms.control.getnextcontrol.aspx[^].

Besides, be careful with modification of default behavior of forms and controls.

[EDIT]

If can be something like:
C#
Panel parent = //... // parent panel, form.., the parent of the controls to be focused
Form form = //... // the form containing controls in question

//...

// focus forward:
Control next = parent.GetNextControl(form.ActiveControl, true);
next.Focus();


—SA
 
Share this answer
 
v3
Comments
abdulsafran 5-Aug-13 2:12am    
Could you please provide sample code for my solution? then I can get better idea of how to correct it.
Sergey Alexandrovich Kryukov 5-Aug-13 10:13am    
What, one line of code? Get next control and call Focus() on the found control...
—SA
abdulsafran 5-Aug-13 4:47am    
I think the problem is I'm using AutoCompleteCustomSource with AutoCompleteMode as SuggestAppend and AutoCompleteSource as CustomSource. That's why enter is not working, please help me?
Sergey Alexandrovich Kryukov 5-Aug-13 10:14am    
Why told you Enter should work (as navigation)? If you implement it, it will...
—SA
abdulsafran 7-Aug-13 10:46am    
Can you provide me sample code for that? because I tried several ways, it won't work.
try using this
C#
private void comboBox1_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.Enter)
            {
                textBox1.Focus();//your control to focus
            }
        }
 
Share this answer
 
v2
Comments
Basmeh Awad 4-Aug-13 16:29pm    
add a break point and debug the programe may be another event is taking focus back to your control..
H.Brydon 4-Aug-13 22:50pm    
Interesting idea, but breakpoint hits change the focus.
abdulsafran 5-Aug-13 2:03am    
Hi Basmesh, I check this, but didn't working, could you please help me?
abdulsafran 5-Aug-13 4:47am    
I think the problem is I'm using AutoCompleteCustomSource with AutoCompleteMode as SuggestAppend and AutoCompleteSource as CustomSource. That's why enter is not working, please help me?
Hi,

I tried the same and it works fine with combo box also. Please check if there is any other event which stops this event from raising.
 
Share this answer
 
Comments
Sergey Alexandrovich Kryukov 4-Aug-13 22:27pm    
Don't post such content as "solution". Comment a solution you are talking about, reply to other comments, use "Improve question"...
—SA
abdulsafran 5-Aug-13 4:47am    
I think the problem is I'm using AutoCompleteCustomSource with AutoCompleteMode as SuggestAppend and AutoCompleteSource as CustomSource. That's why enter is not working, please help me?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900