Link to home
Start Free TrialLog in
Avatar of kranthi4uonly
kranthi4uonly

asked on

combo box default value setting in c# windows form

i had a combobox with 5 items in it the first one is blank
1)
2)a
3)b
4)c
5)d
so my question is  i want to set it to blank if i press spacebar key instead of using up arrow key to set it to balnk (for eg if my combobox is showing "d" i have to press up arrow 4 times to make it balnk instead i want to make it blank by pressing "spacebarkey"

and one more thing the properties of combobox ----dropdownstyle is set to DropDownList
can any one hep me please

Avatar of Jaime Olivares
Jaime Olivares
Flag of Peru image

you can implement a KeyPress event for that combo and detect if keycode is 32 to select first item.
Avatar of kranthi4uonly
kranthi4uonly

ASKER

i had done that
 private void comboBox1_KeyPress(object sender, KeyPressEventArgs e)
        {
            if (e.KeyChar == (char)(Keys.Space))
            {
             // what to do here
            }
thansk for ur reply
also ensure your form has the KeyPreview property set to true
i had done that
 private void comboBox1_KeyPress(object sender, KeyPressEventArgs e)
        {
            if (e.KeyChar == (char)(Keys.Space))
            {
          comboBox1.Text = "";
            }

ASKER CERTIFIED SOLUTION
Avatar of p_davis
p_davis

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial