Question : Determine if comboBox selectedIndex is changed programatically or by user?

Hey all

I have a comboBox, and I am using the selectedIndexChanged event to know when it has been changed.  I populate it with a list of choices when the user enters a row in a datagridview.  This means that the selectedIndexChanged event fires everytime the user enters a new row in the datagridview, not when the user changes the comboBox as I intended.  I would like to be able to determine when the index is changed by the user, filtering out when it's changed by the program.

I read a reply by TheLearnedOne who said the key was to handle the mouseDown and mouseUp events, but I don't know how to do this.  Could anyone post a short example?

Thanks,

Rob

Answer : Determine if comboBox selectedIndex is changed programatically or by user?

I will disagree with the mentioned solution that involves MouseDown/MouseUp events. What if user tabs to combobox control, and uses Up/Down arrow keys to change the currently selected item?

The only thing I can think of is something like this:

class Form1 : Form
{
    bool IsChangedByCode = false;


    void PopulateData()
    {
        IsChangedByCode = true;
        // the code for poulating combobox, or selecting some item
       // ....
       IsChangedByCode = false;
    }

    private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
    {
        if (IsChangedByCode == true) return;
    }
}

Goran
Random Solutions  
 
programming4us programming4us