c# - ComboBox.SelectedIndexChanged is not raised -


I have a form that has only empty combo box, I have set datasource in an empty binding list. When I add something to the compulsory list, then it is selected and compaubux1 Changed index changes, but by changing the index chosen from event combo box 1, in my opinion, not too difficult is raised why not? When a single item is removed, comboBox1_SelectedIndexChanged is removed properly.

  Public Partial Sections Form 1: Form {Public Form 1 () {var test_ = New binding list & lt; Int & gt; (); InitializeComponent (); ComboBox1.DataSource = test_; Console.WriteLine (comboBox1.SelectedIndex); // -1 test_.Add (42); // bug? No comboBox1_SelectedIndexChanged - & gt; 0 console. Light line (combobox selected idx); // test_.Remove (42); // comboBox1 Selected Index Changed - & gt; -1 console. Light line (combobox selected index); // -1} Private Zero ComboBox 1 Select Index changed (Object Sender, EventEurge E) {console. Videline ("index changed" + combo box. Selected indices); }}  

You are not right with your argument

comboBox1.SelectedIndex is -1 does not mean that you have item selected in -1 position!
This means that no item is selected in comboBox1 .

Adding an item, selected index becomes 0 . There is no change on selection because any item was selected at the first position (SelectedIndex = -1)

.


Comments