Note that there are some explanatory texts on larger screens.

plurals
  1. PODifferentiating between events raised by user interaction and my own code
    primarykey
    data
    text
    <p>The <code>SelectedIndexChanged</code> event gets fired in my application from a combo box when:</p> <ol> <li>the user chooses a different item in the combo box, or when:</li> <li>my own code updates the combo box's <code>SelectedItem</code> to reflect that the combo box is now displaying properties for a different object.</li> </ol> <p>I am interested in the <code>SelectedIndexChanged</code> event for case 1, so that I can update the current object's properties. But in case 2, I do not want the event to fire, because the object's properties have not changed.</p> <p>An example may help. Let's consider that I have a list box containing a list of people and I have a combo box representing the nationality of the currently selected person in the list. Case 1 could happen if Fred is currently selected in the list, and I use the combo box to change his nationality from English to Welsh. Case 2 could happen if I then select Bob, who is Scottish, in the list. Here, my list update event-handler code sees that Bob is now selected, and updates the combo box so that Scottish is now the selected item. This causes the combo box's <code>SelectedIndexChanged</code> event to be fired to set Bob's nationality to Scottish, even though it already is Scottish.</p> <p><strong>How can I update my combo box's <code>SelectedItem</code> property without causing the <code>SelectedIndexChanged</code> event to fire?</strong> One way would be to unregister the event handler, set <code>SelectedItem</code>, then re-register the event handler, but this seems tedious and error prone. There must be a better way.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload