Reputation: 14507
I am using combo box in WinForm but when i was selected any item in combo box then selected item background color is blue. i want to remove this blue background color (particularly on form load, tried to set focus to other control in the form, but combo highlight not removed) but item should be selected .
Can anybody help out on this...?
Upvotes: 11
Views: 16989
Reputation: 141
Simple way just Disable the ComboBox and then enable it
combobox.Enabled = false;
combobox.Enabled = true;
and even you select an item inside it the item will still selected but the highlight will go
Upvotes: 1
Reputation: 1995
I came across the same problem and after not finding a working solution I had the same idea as @Vadim K.
Here is a short example.
First step is to to change focus in the UI_Load event.
Private Sub UI_Load(sender As System.Object, e As System.EventArgs) Handles Me.Load
Me.lblTitle.Focus()
End Sub
Next step is to handle the case when someone selects a new value
Private Sub comboExportDates_SelectedIndexChanged(sender As Object, e As EventArgs) Handles comboExportDates.SelectedIndexChanged
Me.lblTitle.Focus()
End Sub
Works fine for me
Upvotes: 0
Reputation: 371
To solve the same I have tried almost EVERYTHING:
DropdownStyle
property to DropdownListthis.BeginInvoke(new Action(() => { comboBox1.Select(0, 0); }));
combobox1.SelectionLength = 0;
comboBox.TabIndex
SendKeys.Send("{ESC}");
because it is not a reliable solutionNothing helped. Maybe because I don't have text in my combobox items, only images. The only stable and working solution was to move a focus on another Label control:
label.Focus();
You could also hide that label.
Upvotes: 5
Reputation: 21
I am not a big VB user, and only play with it in Excel, but also had this problem when a selection was made in my ComboBox. I finally found a way to get rid of the blue text highlighting.
I have a ComboBox on a UserForm. By selecting the ComboBox and viewing the Properties, simply changing the 'HideSelection' to True worked for me. You could also code for it: ComboBox1.HideSelection = True
Upvotes: 2
Reputation: 7
There is an Easy solution for you
private void myComboBox_Paint(object sender, PaintEventArgs e)
{
myComboBoxComboBox.SelectionLength = 0;
}
hope it helps :)
Upvotes: 1
Reputation: 33143
It appears that the only way to do this is by subclassing the combobox control.
Here is an example where someone does that:
http://social.msdn.microsoft.com/Forums/en-US/winforms/thread/e234c4a7-0cf7-4284-a072-8152f7593002/
There are probably more on the web to guide you.
Upvotes: 3
Reputation: 38200
I found something over this site
Create a timer and enable it in your SelectedIndexChanged event, and in the timer just add ComboBox1.Select(0,0)
this should remove the selection part and then disable the timer. Identify other entry points where in you can Enable
the timer again
Code snippet
private void comboBox1_SelectedValueChanged(object sender, EventArgs e)
{
//Get the item selected in the combobox
ComboBox cbx = (ComboBox)sender;
int idx = cbx.SelectedIndex;
string s1 = cbx.SelectedItem.ToString();
// Enable the time so that the Highlight can be removed
timer1.Enabled = true;
}
private void timer1_Tick(object sender, EventArgs e)
{
// Remove the Highlight
comboBox1.Select(0, 0);
// Disable timer
timer1.Enabled = false;
}
Upvotes: 2