ComboBoxEdit.SelectedIndexChanged Event
Occurs when the selection moves from one ComboBoxEditor item to another.
Namespace: DevExpress.XtraEditors
Assembly: DevExpress.XtraEditors.v24.1.dll
NuGet Package: DevExpress.Win.Navigation
Declaration
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.
Example
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.
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.FontStyleDelta = selectedFontStyle;
}
}
Related GitHub Examples
The following code snippet (auto-collected from DevExpress Examples) contains a reference to the SelectedIndexChanged event.
Note
The algorithm used to collect these code examples remains a work in progress. Accordingly, the links and snippets below may produce inaccurate results. If you encounter an issue with code examples below, please use the feedback form on this page to report the issue.