Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ComboBox events: SelectedIndexChanged vs. SelectedValueChanged

Tags:

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?

like image 390
kodkod Avatar asked Jan 27 '11 15:01

kodkod


2 Answers

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.

like image 107
Matt Avatar answered Sep 21 '22 07:09

Matt


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.

like image 1
Peter Avatar answered Sep 19 '22 07:09

Peter