RepositoryItemComboBox.SelectedIndexChanged Event

Occurs on changing the index of the selected value in the combo box editor.

Namespace: DevExpress.XtraEditors.Repository

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 event occurs on changing the value of the ComboBoxEdit.SelectedIndex property. This property denotes the index of the selected value, which is provided by the ComboBoxEdit.SelectedItem property and displayed in the control's edit box.

The index of the selected value is changed when:

You can handle the SelectedIndexChanged event in order to get notifications that the user has selected another item from the RepositoryItemComboBox.Items collection.

If the currently selected value does not exist in the item collection (i.e. ComboBoxEdit.SelectedIndex is -1) and the newly selected value does not also belong to the collection, the SelectedIndexChanged event is not fired since the value of the ComboBoxEdit.SelectedIndex property remains -1. However, in this case, the RepositoryItem.EditValueChanging and RepositoryItem.EditValueChanged events still occur.

 

Assume you have a combo box editor displaying two items: 'Frankfurt' and 'London' and the end-user is able to change the text in the edit region of the combo box (the RepositoryItemButtonEdit.TextEditStyle property is set to true). The currently selected item is 'Frankfurt' and ComboBoxEdit.SelectedIndex is 0.

If the user presses the 'A' key, the combo box looks through items and tries to locate the item starting with 'A' (the RepositoryItemComboBox.AutoComplete property must be set to true). Since this item cannot be found, the selected value is set to 'A', the index of the selected value is set to -1 and the SelectedIndexChanged event is fired. THe RepositoryItem.EditValueChanged event is also fired as a result of changing the edit value which matches the selected value.

Pressing the 'm' key changes the selected value to 'Am'. The value of ComboBoxEdit.SelectedIndex does not change and the SelectedIndexChanged event is not fired. However, the RepositoryItem.EditValueChanged event still occurs.

 

The editor's ComboBoxEdit.SelectedIndexChanged event is equivalent to the current event.

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