Click here to Skip to main content
15,886,110 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello to all,

I am working in one window application , I have one DropDownlist control in it. when i set focus on dropdown and use up/down key value of dropdown is change...

Should i stop this?

If possible than how ? please help me if possible this thing ....


Thanks and Regards

JD
Posted
Comments
CHill60 21-Apr-14 8:50am    
Not sure what your oroblem is. That would be expected behaviour?
SOHAM_GANDHI 21-Apr-14 9:23am    
you can use key event for dropdown list, you prevent up/down key event

You should not stop this. Because this is the default behaviour.
If somebody wants to fill the form with keyboards only, then what would he/she do?
 
Share this answer
 
Comments
Jay1902 21-Apr-14 9:08am    
That's right but i want to create one shortcut key Ctrl + Up Arrow for another control but it's not work and it's only get as a up Arrow key and change the value of dropdownlist
I guess you need to do with some other key.
Manas Bhardwaj 21-Apr-14 14:57pm    
Good advice +5!
Thanks Manas. :)
Just check the key pressed event for dropdownlist for example given below:

C#
protected override void OnPreviewKeyDown(KeyEventArgs e)
            {
                if (IsReadOnly)
                {
                    if (e.Key == Key.Down || e.Key == Key.Up)
                    {
                        e.Handled = true;
                        return; // do not call the base class method OnPreviewKeyDown()
                    }
                }

                base.OnPreviewKeyDown(e);
            }
 
Share this answer
 
Quote:
That's right but i want to create one shortcut key Ctrl + Up Arrow for another control but it's not work and it's only get as a up Arrow key and change the value of dropdownlist


you need to set form's KeyPreview property to true

C#
this.KeyPreview = true;


by setting above property form will receive key events before the event is passed to the control that has focus.
 
Share this answer
 
Hi Jay,

It is default behaviour of dropdown to change the selected values with up / down arrow keys. But these could be skipped by using the below code

private void ComboBox1_KeyDown(object sender, KeyEventArgs e)
{
if (e.KeyCode == Keys.Up || e.KeyCode == Keys.Down)
{
e.SuppressKeyPress = true;
}
}
 
Share this answer
 

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