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.v20.1.dll

Declaration

[DXCategory("Appearance")]
[DefaultValue(-1)]
public virtual int SelectedIndex { get; set; }
<DXCategory("Appearance")>
<DefaultValue(-1)>
Public Overridable Property SelectedIndex As Integer

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;   
            }
        }
See Also