Click here to Skip to main content
15,886,799 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i have combo boxex for date of birth in my winform app,the default text in these boxes are day,month and year,how can i prevent the user from writing in it and how can i perform check if none of the value is not selected from comboboxes??
Posted

In designer view set your combo box's DropDownStyleproperty to DropDownList or by code:
C#
myCombo.DropDownStyle = ComboBoxStyle.DropDownList;


You can check whether some value is selected or not by checking SelectedIndex or SelectedValue property, it depends on how do you fill data into your combo boxes.

C#
if(myCombo.SelectedIndex != -1)
{
    //do something
}

//or

if(myCombo.SelectedValue != null)
{
    //do something
}
 
Share this answer
 
v2
Comments
Nainaaa 12-Aug-14 8:31am    
thanks....
but i also want that default text e.g month should also shown on combobox until user select any value from list.
Oshtri Deka 12-Aug-14 8:39am    
Just set combos after filling to some default value or index.
For instance monthCombo.SelectedIndex = 0 and adjust above mentioned checks accordingly.
Good luck!
Set your combo as DropDownList:

C#
this.comboBoxType.DropDownStyle = ComboBoxStyle.DropDownList;
 
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