本文共 1203 字,大约阅读时间需要 4 分钟。
l SelectionChangeCommitted事件在设定datasource和displaymember和valuemember时,以及手动改变combobox索引和值时都不触发该事件, 只是在界面选择combobox不同值时触发2 SelectedIndexChanged事件 索引改变时触发3 SelectedValueChanged事件 值改变时触发设置DataSource, DisplayMember, ValueMember不同顺序触发SelectedIndexChanged事件和SelectedValueChanged事件的次数顺序一:this.comboBox1.DisplayMember = "userName"; (不触发)this.comboBox1.ValueMember = "userAge"; (只触发SelectedValueChanged)this.comboBox1.DataSource = dt; (都触发)SelectedValueChanged触发两次(总是先触发)SelectedIndexChanged,触发一次 (设置DisplayMember属性时不触发两种事件)顺序二:this.comboBox1.ValueMember = "userAge";this.comboBox1.DisplayMember = "userName";this.comboBox1.DataSource = dt;同上顺序三:this.comboBox1.DataSource = dt; (都触发)this.comboBox1.DisplayMember = "userName";(都触发)this.comboBox1.ValueMember = "userAge";(只触发SelectedValueChanged事件)SelectedValueChanged触发三次(总是先触发)SelectedIndexChanged,触发两次 (设置DisplayMember属性时不触发两种事件)顺序四:this.comboBox1.DataSource = dt; (都触发)this.comboBox1.ValueMember = "userAge";(都触发) 其中SelectedValueChanged触发两次this.comboBox1.DisplayMember = "userName";(都触发)SelectedValueChanged触发四次(总是先触发)SelectedIndexChanged,触发三次 (设置DisplayMember属性时不触发两种事件) |
转载于:https://www.cnblogs.com/wyh167/archive/2013/01/10/2855038.html