Click here to Skip to main content
15,867,771 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hello,

In my project I am using a Navigate Function which is used to navigate between controls by Enter, Down and Up key.

When I use it on ComboBox the focus moves to next control, but SelectedItem of ComboBox is changed.

(Example:- If There are 3 itmes in combobox 'a','b','c' and if 'b' is selected, If I press Up, focus goes to previous control of ComboBox and item in ComboBox changed to 'a' and if Down is pressed focus goes to next control and item in ComboBox changed to 'c'. However if I press enter focus goes to next control and selectedItem remain as it is.

I am trying to get functionality on Up and Down Key to Move Previous Or Next Control and on combination of Alt-Down select item from list

How to Do this? Is there any property is present if I have to this logically then what's the way?
Posted
Updated 18-Apr-11 1:28am
v2

Don't do it! This is as simple as that. You user will hate it. Do not override common UI behavior; standard navigation is too important to sacrifice.

—SA
 
Share this answer
 
Comments
Yatin Bhagat 19-Apr-11 6:39am    
but what if it is a Specific Requirement of Client??????
Sergey Alexandrovich Kryukov 19-Apr-11 13:18pm    
Talk to the Client; they should understand!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! :-)
Demonstrate better design, show them, say gently "isn't that better?"...

--SA
Yatin Bhagat 21-Apr-11 8:54am    
like it!!!!!
my clients use a dos based software developed in foxpro and they the flow is very fast on arrow keys and enter key...and they got habbited of using that way....so place such kind of requirments
Sergey Alexandrovich Kryukov 21-Apr-11 16:25pm    
It would only benefit your clients, but I no how heavily some people are preoccupied with their imprinted views... using DOS and FoxPro is itself a clinical symptom :-)

So, will you consider to formally accept this answer anyway?
Thank you,
--SA
You need to set the KeyPreview property of Form to true. This will make all the keys come to the Form before reaching any of the child controls. In addition to that, you will have to handle KeyUp, KeyDown messages for your main Form as well and in the handling of those, you will have to mark those as Handled if your Combobox is in focus.

C#
private void Form1_KeyDown(object sender, KeyEventArgs e)
{
    if (comboBox1.Focused)
        e.Handled = true;
}


Here is a link from MSDN which explains this KeyPreview property in detail with examples: Link here[^]
 
Share this answer
 
v2
Comments
Aamir Butt 19-Apr-11 0:56am    
Somebody care to explain why is this down-voted?
Try this.
private void comboBox1_KeyUp(object sender, KeyEventArgs e)
        {
            e.Handled = true;
            previous_contol_id.Focus();
        }
        private void comboBox1_KeyDown(object sender, KeyEventArgs e)
        {
            e.Handled = true;
            next_contol_idbutton1.Focus();
        }
 
Share this answer
 
Comments
Henry Minute 18-Apr-11 7:31am    
I think that you have misunderstood what KeyUp and KeyDown do. They do not handle the Up and down keys, they handle any of the keyboard keys being pressed (down) or released (up).
#realJSOP 18-Apr-11 8:53am    
I'm pretty sure he means the arrow keys themselves, not the keyup/down events.
Yatin Bhagat 18-Apr-11 13:56pm    
yes exactly...i am asking about Up and Down Keys...But I got hint from this ...Thank you

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