Hello
How to prevent user to write in comboBox? I just need to allow the user to select from the list.
If I set DropDownStyle property to DropDownList, this will work, but I want to keep DropDownStyle = DropDown.
Also, How to prevent a user to write in a textbox without disable it. I have a textbox which will display an output. I need to keep it enabled but not allowing the user to write in.
I tried to set locked property to true as well, but this didn't work. Any idea?
How to prevent user to wirte in a comboBox or a textBox
3 Answers
Know the answer? Post it. Somebody with the same question will find it here.

Hemant SrivastavaRank #581 · 4.2K reputationPosted Nov 5, 2013, 6:35 AM EST
private void txtBx_KeyPress(object sender, KeyPressEventArgs e)
{
e.Handled = true;
}
private void comboBox2_KeyPress(object sender, KeyPressEventArgs e)
{
e.Handled = true;
}
Rano AH125 reputationPosted Nov 5, 2013, 7:25 AM EST
Ablafizi Kibiki15 reputationPosted Nov 5, 2013, 8:17 AM EST
protected void Page_Load(object sender, EventArgs e)
{
TextBox1.Attributes.Add("readonly", "readonly");
}