user3560351 user3560351 - 1 year ago 123 Question

How to remove highlight of combobox when an Item is selected in Vb?

In load page event:

I read some data from DB and then add this data to Combo box then select an item as default and enable of combo box changes to false.
When I load this page, the item witch selected highlights with blue color.

How to remove this highlight?

Answer Source

You can modify its SelectionLength property, which gets or sets how many characters have been selected (highlighted).

Just set it to 0 after you have selected the default item and you should be good to go:

ComboBox1.SelectionLength = 0


In your case this code is executed before the Load event has finished. Due to this the form has not been rendered yet, which is why it is not working for you.

The simple fix is to add this in the form's Shown event too:

Private Sub Form1_Shown(sender As Object, e As System.EventArgs) Handles Me.Shown
    ComboBox1.SelectionLength = 0
End Sub

If you don't want the caret to be in the beginning you can also add this line to set it to the end of the text:

ComboBox1.SelectionStart = ComboBox1.Text.Length
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download