ComboBoxEdit.SelectedIndexChanged Event

Occurs when the selection moves from one ComboBoxEditor item to another.

Namespace: DevExpress.XtraEditors

Assembly: DevExpress.XtraEditors.v20.1.dll

Declaration

[DXCategory("Events")]
public event EventHandler SelectedIndexChanged
<DXCategory("Events")>
Public Event SelectedIndexChanged As EventHandler

Event Data

The SelectedIndexChanged event's data class is EventArgs.

Remarks

The SelectedIndexChanged is identical to the RepositoryItemComboBox.SelectedIndexChanged event available through the ComboBoxEdit.Properties group.

Refer to the RepositoryItemComboBox.SelectedIndexChanged topic for more information.

NOTE

This event fires only when the selected item changes. Although modifying the editor's item collection may also indirectly change the ComboBoxEdit.SelectedIndex property value (e.g., when you insert an item before the currently selected one), these modifications do not trigger the SelectedIndexChanged event.

IMPORTANT

The SelectedIndexChanged does not fire when a previous and a currently selected items are equal objects.

Examples

Consider a combo box editor displaying different font styles (regular, bold, italic, underline, strikeout). When you select an item from the dropdown list, a corresponding font style is applied to the combo box editor.

Combo box items in this example represent strings identifying names of specific font styles. In the ComboBoxEdit.SelectedIndexChanged event handler, we determine the currently selected item and convert it to a corresponding value of type FontStyle. Then the new font is applied to the editor.

The following image shows a combo box editor when the Underline item is selected.

ComboBox_SelectedindexChanged_example

  comboBoxEdit1.EditValue = "Regular";
  comboBoxEdit1.Properties.Items.AddRange(new object[] 
    {"Bold", "Italic", "Regular", "StrikeOut", "Underline"});
  comboBoxEdit1.SelectedIndexChanged += new System.EventHandler(
    this.comboBoxEdit1_SelectedIndexChanged);
//...
 private void comboBoxEdit1_SelectedIndexChanged(object sender, EventArgs e) {
     EnumConverter ec = TypeDescriptor.GetConverter(typeof(FontStyle)) as EnumConverter;
     var cBox = sender as ComboBoxEdit;
     if (cBox.SelectedIndex != -1) {
         FontStyle selectedFontStyle = (FontStyle)ec.ConvertFrom(
           cBox.Properties.Items[cBox.SelectedIndex]);
         cBox.Properties.Appearance.Font =
           new Font(cBox.Properties.Appearance.Font, selectedFontStyle);
     }
 }
See Also