Reputation: 361
I wrote a code that whenever the user picks a value from the drop-down comboBox, their choice becomes the first item (index 0) of the collection.
Example
BEFORE
[_ MyComboBox _][v]
|Dog |Tree |House
USER CLICKS "Tree"
AFTER
[_ MyComboBox _][v]
|Tree |Dog |House
The problem is that after this operation, even though everything works fine, the comboBox remains blank and the user has no clue about what they've done.
But if I do as everyone suggests, that is MyComboBox.SelectedIndex = 0;
it triggers an inifinite loop since I'd be calling it from inside the event handler MyComboBox_SelectedIndexChanged(...)
I also tried MyComboBox.Text = string_that_contains_what_I_want_to_display;
but it triggers BOTH SelectedIndexChanged AND SelectedValueChanged.
Frankly I cannot understand why even switching from items with the same value, BOTH index and value are triggered. As far as I understand, SelectedValueChanged should only be triggered when the two items have different content.
I'd be thankful to anyone that will help me get out of this puzzle.
I just need to show the result of the sort operation in the program interface, after it's done. I could reload the whole page containing my control: it would work, but that wouldn't be very efficient.
Upvotes: 2
Views: 1807
Reputation: 155045
Use the SelectionChangeCommitted
event instead of SelectionChange
. The SelectionChangeCommitted
event is only fired when the user makes a change rather than when your program makes the change for it.
Upvotes: 8