In the context of a data-bound ComboBox
whose ValueMember
and DisplayMember
properties are 开发者_运维技巧appropriately set:
Is there a difference between the SelectedIndexChanged
and the SelecetedValueChanged
events? Are they fired simultaneously when an item is selected from the drop-down list of the ComboBox
?
Well, just because your index changes doesn't necessarily mean that your value must change.
This also may not be the most realistic scenario because design-wise this implementation would be bad.
Let's say you are displaying a ComboBox
where you are displaying body parts. However, you may be exporting or storing this information in a format mapped to integer values. Therefore, your ComboBox
may display "Left Arm" and "Right Arm" which are mapped to a value of 5, which defines (5 = Upper Body) in its mapping. Then, if the user switched "Right Arm" to "Left Arm" there is no value change; however the SelectedIndex
has changed.
So I guess it is a case by case basis, but these events surely could function differently depending on the case.
The difference is that SelectedItemChange will be -1 if you edit the combobox ea its not part of the indexed values. However as soon as you start typing in the combobox it will fire value change event.
ea you could use value change to fire events that will reformat text input in a domainupdown control. And if someone edits a domainupdown control and it value becomes -1 you could collect new items to its list (by press of a button and using domainupdown.text property.
精彩评论