Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

I have ComboBox control(WinForm project).

When I bind DataSource to the ComboBox control combobox_selectedindexchanged event is fired.

Any idea how to prevent selectedindexchanged event when DataSource is bound?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
344 views
Welcome To Ask or Share your Answers For Others

1 Answer

Remove the handler for the SelectedIndex_Changed event, bind your data, then add the handler back. Following is a simple example of how this might be done within a method:

private void LoadYourComboBox()
{
    this.comboBox1.SelectedIndexChanged -= new EventHandler(comboBox1_SelectedIndexChanged);


        // Set your bindings here . . .


    this.comboBox1.SelectedIndexChanged += new EventHandler(comboBox1_SelectedIndexChanged);
}

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...