Click here to Skip to main content
15,867,453 members
Please Sign up or sign in to vote.
1.11/5 (3 votes)
See more:
Hi all,

I am a total newbie in C#. I have added a combo box in my window forms. But I found it the text in the combo box is editable during runtime.
but i do not want to change my combobox DropDownStyle property to DropDownList

is there any other way to make it un-editable?

help me...
Posted
Comments
CHill60 21-Oct-14 8:16am    
Why don't you want to use the accepted method of changing that property?
SRS(The Coder) 21-Oct-14 9:00am    
ComboBox, the name itself describes that it is the combination of both DropDown and TextBox. So I don't think there would be any way to make it non-editable at all.

I don't understand why you want to do this, and I consider this code a hack ... but:
C#
private void YourComboBox_KeyPress(object sender, KeyPressEventArgs e)
{
    e.Handled = true;
}
 
Share this answer
 
Comments
SRS(The Coder) 21-Oct-14 9:02am    
Yes, this might be a option to do.
A ComboBox, as the name suggests, is a combined control. You might use directly a TextBox plus a ListBox to fulfill your requirements.
 
Share this answer
 
Comments
BillWoodruff 21-Oct-14 8:47am    
I think, in this case, since the OP doesn't want the user to edit the Text, a Label would be a better choice for a composite UserControl.
CPallini 21-Oct-14 9:03am    
Yes, you are right. A read only TextBox also would fit the job.

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