Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 95677
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 10, 20262026-05-10T23:41:44+00:00 2026-05-10T23:41:44+00:00

It seems like when you have a WinForms .NET application, and a ComboBox (set

  • 0

It seems like when you have a WinForms .NET application, and a ComboBox (set to the ‘DropDown’ style), and that ComboBox has multiple items in it that are identical, weird things happen. Specifically, the index of the selected item can change without firing the SelectedIndexChanged event.

Of course, this causes mass confusion and weird, obscure errors, which is what I’ve been pulling my hair out over lately.

Here’s a simple example you can use to see what I’m talking about:

  • Make a new .NET WinForms project (I use VB.NET, but feel free to translate – it’s simple enough).
  • Drop a ComboBox, a button, and a TextBox (set MultiLine=True) onto the form.
  • Use the following code to load the ComboBox with 3 identical items and to print some status messages when the SelectedIndexChanged event fires, and to see what the currently selected index is (via a button):
Private Sub ComboBox1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ComboBox1.SelectedIndexChanged         TextBox1.Text = TextBox1.Text & vbNewLine & 'ComboBox SelectedIndexChanged event fired.' & vbNewLine & _             'SelectedIndex is: ' & ComboBox1.SelectedIndex     End Sub      Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load         ComboBox1.Items.Add('John Doe')         ComboBox1.Items.Add('John Doe')         ComboBox1.Items.Add('John Doe')      End Sub      Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click         TextBox1.Text = TextBox1.Text & vbNewLine & _         'Button clicked.' & vbNewLine & _         'SelectedIndex is: ' & ComboBox1.SelectedIndex     End Sub

Run the project and select an item from the ComboBox (say, the middle one). Then, click the ComboBox’s drop-down arrow, but DON’T SELECT ANYTHING. Click the Button (Button1 by default) and see what it says.

Unless I’ve lost my mind, here’s what you should see:

ComboBox SelectedIndexChanged event fired. SelectedIndex is: 1 Button clicked. SelectedIndex is: 0

In other words, the SELECTED INDEX HAS CHANGED but without the SelectedIndexChanged event firing!

This only happens when the items in the ComboBox are identical. If they’re different, this doesn’t happen. (It also doesn’t happen if the ComboBox’s ‘DropDown’ style is set to ‘DropDownList.’)

I suspect this may be a bug in the .NET framework itself and not something I can fix, but on the off chance that anyone else has any ideas on what to do here (or what I might be doing wrong!), please chime in! I’m at a loss to explain this behavior or work around it (I expect the SelectedIndex to stay the same unless, y’know, you actually CHANGE it by selecting something else!)

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. 2026-05-10T23:41:45+00:00Added an answer on May 10, 2026 at 11:41 pm

    The .NET Framework does not actually keep track of the selected index of the combo box’s drop down list; this is handled internally by the Windows API. As a consequence of this, .NET is reliant on the Windows API to notify it when the selected index changes by means of a notification message sent to the combo box’s window handle, so that it can in turn fire the SelectedIndexChanged event.

    Unfortunately, it turns out that the particular notification message that .NET watches for (CBN_SELCHANGE to be exact) does NOT cover all possible scenarios in which the selected index could change. Specifically, CBN_SELCHANGE is only sent by the Windows API if the user clicks on, or selects using the arrow keys, an item in the drop down list. However, in a DropDown style combo box, the act of opening the combo box causes Windows to look at the text in the edit portion of the combo box, search through the list of items for a match, and if a match is found, automatically select the matching item (or the first matching item, if there are multiple matching items). This can change the selected index, but does NOT send a CBN_SELCHANGE notification message, so .NET misses the fact that it changed and does not fire the SelectedIndexChanged event.

    Windows does all this in a DropDown style combo box because the user does not HAVE to pick something in the drop down list; they can type whatever they want. So each time you open the combo box it assumes that the user might have changed the text and tries to re-sync with what’s in the list if it can.

    In your case, when you open the combo box for the second time, it is re-syncing and selecting the first match for the text in the edit portion, which is ‘John Doe’ #0, and changing the selected index to 0 without .NET being aware.

    So it basically is a bug in the .NET Framework. Unfortunately, there is no perfect workaround — you can’t get Windows to not do the re-sync, and there is no event that fires right after the re-sync occurs in which you can get the new selected index. (The DropDown event actually fires right before the re-sync occurs, so it will not see the new index.) About the best you can do is handle the DropDownClosed event, assume that the index might have changed at that point, and act accordingly.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 96k
  • Answers 96k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer It sounds like you're trying to call methods on an… May 11, 2026 at 7:09 pm
  • Editorial Team
    Editorial Team added an answer The second option is the correct one. You could also… May 11, 2026 at 7:09 pm
  • Editorial Team
    Editorial Team added an answer I haven't worked on the .NET platform in awhile, so… May 11, 2026 at 7:09 pm

Related Questions

I am working on a VB.NET WinForms app that was upgraded by Visual Studio
Hiya - been pointed at you guys by a friend of mine. I have
Greetings, I have two questions regarding a DataTable.Select(): 1) How to escape potential apostrophes
Our marketing department comes back with active directory integration being a key customer request,

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.