ComboBoxEdit.SelectedIndex Property
Gets or sets the index of the selected ComboBox item. This index specifies the item position inside the RepositoryItemComboBox.Items collection.
Namespace: DevExpress.XtraEditors
Assembly: DevExpress.XtraEditors.v24.2.dll
Declaration
[DefaultValue(-1)]
[DXCategory("Appearance")]
public virtual int SelectedIndex { get; set; }
Property Value
Type | Default | Description |
---|---|---|
Int32 | -1 | The zero-based index of the edit value in the RepositoryItemComboBox.Items collection; otherwise, -1. |
Remarks
To get or set the selected ComboBoxEdit item, you can also use the the ComboBoxEdit.SelectedItem property. This property accepts item values instead of their indexes.
If the editor’s edit value refers to an item that does not exist in the RepositoryItemComboBox.Items collection, the SelectedIndex property returns -1.
If you set SelectedIndex to an invalid index (less than zero or bigger than than the last item index), the ComboBoxEdit.SelectedItem property is set to null and the edit box displays an empty string.
Example
The following code illustrates how to automatically select the first ComboBoxEdit item when a user activates a Data Grid cell.
private void gridView1_ShownEditor(object sender, EventArgs e)
{
GridView currentView = sender as GridView;
ComboBoxEdit cmbPO = currentView.ActiveEditor as ComboBoxEdit;
//.............
if (cmbPO.Properties.Items.Count > 0)
{
cmbPO.SelectedIndex = 0;
}
}
Related GitHub Examples
The following code snippets (auto-collected from DevExpress Examples) contain references to the SelectedIndex property.
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.