ComboBox text is highlighted until the box is accessed

I have several ComboBoxes in my program, and the ones that have text already in the box end up highlighted.  This is true even looking at the form in Visual Studio (see attached).  Is there a way to keep the text from being highlighted?  The text in these boxes are highlighted when the program is launched.
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Éric MoreauSenior .Net ConsultantCommented:
How do you feed theses controls? What other properties are set?
BrianAuthor Commented:
Here's the property settings I have changed:

Anchor - Top
AutoCompleteCustomSource - Collection
AutoCompleteMode - SuggestAppend
AutoCompleteSource - ListItems
FormattingEnabled - True
Margin - 3, 2, 3, 2
Modifiers - Friend
TabIndex - 2
Text - White

All other settings are the defaults.
NorieAnalyst Assistant Commented:
How are you populating them?
Become a Microsoft Certified Solutions Expert

This course teaches how to install and configure Windows Server 2012 R2.  It is the first step on your path to becoming a Microsoft Certified Solutions Expert (MCSE).

Éric MoreauSenior .Net ConsultantCommented:
Is that a plain-old combo box? or one from a third party? or one that you have inherited?

I don't have the same behavior.
BrianAuthor Commented:
It's a plain-old combo box, but I do have it on a panel.  I noticed that when I add text in the Text property under a Combo Box that's not on the panel, it does get highlighted.
Éric MoreauSenior .Net ConsultantCommented:
Really strange. I have added a panel to my dummy project and I still don't have your issue!

Which version of VS do you have? I have VS2017.
BrianAuthor Commented:
I have VS2015, but I have a feeling that it's not the version.  I wonder if it could be a setting on the panel?  I don't see anything unusual with the settings.  The TabIndex on the panel is 5, but the TabStop is set to false, so I don't think that would be an issue.  It's odd that all 4 of those combo boxes on the panel are highlighted.  It must be related to the panel.

Strange... I changed the TabIndex to 100 and it had no affect.  I closed and reopened the project and text in the combo boxes are no longer highlighted in VS, but when I run the program, they are still highlighted.  I have done a lot of moving around on the form...  I think I added the panel later, move the controls onto it.  I also removed some things from the form and moved the panel and controls around.  At some point something bazaar must have happened.
Éric MoreauSenior .Net ConsultantCommented:
I found something. In my demo sample, I was not setting the Anchor property. It appears that this is your issue. I have been able to replicate your behavior in VS2017.

The solution is waiting for you at
it is the edit control part of the combobox which has the EM_NOHIDESEL style bit set, what makes the selection to be hilited even if the control doesn't have the focus.

you can get a handle to the edit box by calling like

Dim hwndCBEdit as IntPtr
hwndCBEdit = GetDlgItem(myComboBox.Handle, 1001) 

Open in new window

and hide or show selection by

Dim fchangeNoHideSel as IntPtr
fchangeNoHideSel  = IntPtr.Zero

' Hide:
SendMessage(hwndCBEdit, EM_HIDESELECTION, New IntPtr(1), fchangeNoHideSel)
' Show:
SendMessage(hwndCBEdit, EM_HIDESELECTION, IntPtr.Zero, fchangeNoHideSel)

Open in new window

note, with the 3rd argument fchangeNoHideSel you could try to change the EM_NOHIDESEL style bit permanently for the edit control.

if set to 1 it should update the EM_NOHIDESEL style permanently to 'hide selection' or 'no hide selection'. if that works you should need to call the SendMessage only once.

fchangeNoHideSel  = New IntPtr(1)
' Hide and set EM_NOHIDESEL style bit
SendMessage(hwndCBEdit, EM_HIDESELECTION, New IntPtr(1), fchangeNoHideSel)

Open in new window


Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
BrianAuthor Commented:
Thank you both for your help!  Sara, your method is probably the more correct way to solve the issue, but a little advanced for me.  I'm just a casual programmer at best! :)  Anyway, I found a solution that works for me.  Here's what I've done...

        cbPaperColor.Focus()            '// Temp focus to remove highlighting
        cbPaperSize.Focus()             '// Temp focus to remove highlighting
        cbColorOrBlacknWhite.Focus()    '// Temp focus to remove highlighting
        cbStapled.Focus()               '// Temp focus to remove highlighting
        txtBuilding.Focus()             '// Give focus to building combo box

Open in new window

I set focus on each one, then take focus away.  Problem solved!
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic.NET

From novice to tech pro — start learning today.