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
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
you can implement a KeyPress event for that combo and detect if keycode is 32 to select first item.
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
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
ASKER
i had done that
private void comboBox1_KeyPress(object sender, KeyPressEventArgs e)
{
if (e.KeyChar == (char)(Keys.Space))
{
comboBox1.Text = "";
}
private void comboBox1_KeyPress(object sender, KeyPressEventArgs e)
{
if (e.KeyChar == (char)(Keys.Space))
{
comboBox1.Text = "";
}
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.