Click here to Skip to main content
15,881,455 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am having a combobox.
When I select any option the option should not be highlighted.

How to do this using C#
Posted
Updated 8-Aug-22 14:55pm

The simplest method to use is to pass the focus from your combobox to another control. for an example you can place the following code in the combo box selection change event, assuming you have another combobox:
C#
private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
{
    comboBox2.Focus();
}

Another simple method is to place the following code in your forms Paint event.
C#
private void myForm_Paint(object sender, PaintEventArgs e)
{
    comboBox1.SelectionLength = 0;
}
There really isn't a built in method for doing what you ask and I've seen numerous work arounds that become rather large for such a simple effect. The methods above are what I would use.

Good luck.
 
Share this answer
 
v2
Comments
Volynsky Alex 4-Apr-14 17:26pm    
Good answer!
robertd903 8-Aug-22 20:56pm    
What if you set the focus to another control--yet the ComboBoxes are all STILL highlighted?

Is there really NO property that tells the ComboBox, "Okay, you can turn the highlighting ON/OFF now?"

I hope that the only way to resolve this issue is NOT going to be another "work-around."
ADD this code in css

C#
*:focus
{
    outline: none;
}
 
Share this answer
 
Comments
KUMAR619 4-Apr-14 5:29am    
Thanks but I want for windows forms

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