0

Consider a very basic form with a simple combo box

public partial class Form1 : Form
{
    public Form1()
    {
        InitializeComponent();
        this.comboBox1.Items.Add("test1");
        this.comboBox1.Items.Add("test2");
        this.comboBox1.Items.Add("test3");
    }

    private void Form1_Load(object sender, EventArgs e)
    {
        this.comboBox1.SelectedIndexChanged += (o, args) => 
        {
            MessageBox.Show("Combo box changed!");
        };
    }
}

I have even changed the eventhandler to the below code. (Based on the linked question. Still the same problem)

this.comboBox1.SelectedValueChanged += (o, args) => //or even `Textchanged` event too
            {

                MessageBox.Show("Combo box changed!");
            };

Expand the dropdown using mouse and select any item using keyboard.

The combo-box fires twice (The message box appears twice)

Any ideas why?

1 Answers1

0

Seems like this is a bug with the underlying framework.

So, I managed to get a work around of the issue.

Here's how:

  1. Have a private variable (preferably) which can store the value of the selected item in the combo-box
  2. Next time, compare it with the current selection in the combo-box. If they are same, just return.