Click here to Skip to main content
15,881,172 members
Please Sign up or sign in to vote.
4.78/5 (2 votes)
See more:
How do I make a combobox readonly in C# Windows forms?
Posted
Comments
Sergey Alexandrovich Kryukov 18-Aug-12 3:19am    
Readonly all the time? Then why?
--SA
Arsalaan Ahmed 18-Aug-12 3:36am    
All the Time
ridoy 18-Aug-12 3:49am    
Then you can use textbox,why you need combobox if you want to read only it?

For a combo box, this is a strange requirement, if you think about it. No wonder, there is no such feature if System.Windows.Forms. Anyway, please see this CodeProject article:
ComboBox with read only behavior[^].

—SA
 
Share this answer
 
Comments
Espen Harlinn 18-Aug-12 12:38pm    
Good point :-D
Sergey Alexandrovich Kryukov 18-Aug-12 12:44pm    
Thank you, Espen.
--SA
bchiemara 18-Nov-21 21:32pm    
I need to be able to lock a combobox as part of a trial key expiring and features being disabled which include changing or selecting other items in the combobox which is forced to the first item (as long as there are at least one item in the combobox)...so it isn't that strange of a requirement for what I'm doing, considering the user could add many items to the combobox during the trial. I just swap mine with a label that is populated with the current combobox selected item text. The user doesn't need to interact with the text in using my app, they just need to see what is selected.
The use of the term readonly is confusing. If your aim is to prevent the user editing the text then use the DropDownStyle DropDownList.

See ComboBoxStyle[^]

Alan.
 
Share this answer
 
hii ,
similar thread is

Read only ComboBox[^]
 
Share this answer
 
I think you are talking about this.

You will be able to select items from drop down list,but you can't edit it.
C#
cmbTemplate.DropDownStyle = ComboBoxStyle.DropDownList;
 
Share this answer
 
v2
You have to set the enabled property of the combobox to false.

C#
ComboBox1.Enabled=false;
 
Share this answer
 
Comments
Arsalaan Ahmed 18-Aug-12 3:49am    
we use this property ComboBox1.Enabled=false;
then combo box is hide,,
Santhosh Kumar Jayaraman 18-Aug-12 3:50am    
You are talking about visible property.. am saying about enable/disable property
Arsalaan Ahmed 18-Aug-12 3:50am    
We want to make a read Only combobox.
ridoy 18-Aug-12 3:50am    
No,combobox will be hide if you use ComboBox1.Visible=false
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.

Or you may go for enforce not to write anything into box on keypress, by handling the keypress event to do nothing or to avoid type it in combobox.
Ex :-
C#
private void cmbTest_KeyPress(object sender, KeyPressEventArgs e)
{
    e.Handled = true;
}
 
Share this answer
 
Comments
CHill60 21-Oct-14 9:10am    
Bit late with this
SRS(The Coder) 22-Oct-14 0:28am    
:-)

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