Ian Ringrose
Ian Ringrose

Reputation: 51927

How do I know if the USER changed the Selected Item in ComboBox?

The issue is that the SelectedIndexChanged event is called both when the user makes the change and when the change is made by the application code setting SelectedItem.

Is there a way to tell if the item was changed by the direct actions of the user from the mouse or keyboard?

Upvotes: 3

Views: 383

Answers (1)

MethodMan
MethodMan

Reputation: 18863

Try something like this SelectedChangeCommitted MSDN

private void comboBox1_SelectionChangeCommitted(object sender, EventArgs e)
{

    ComboBox comboBox = (ComboBox) sender;

    // Change the length of the text box depending on what the user has 
    // selected and committed using the SelectionLength property.
    if (comboBox.SelectionLength > 0)
    {
        textbox1.Width = 
            comboBox.SelectedItem.ToString().Length *
            ((int) this.textbox1.Font.SizeInPoints);
        textbox1.Text = comboBox.SelectedItem.ToString();
    }
}

Upvotes: 1

Related Questions