windowsforms-devexpress-dot-xtraeditors-dot-comboboxedit-1af98965.md
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.v25.2.dll
NuGet Package : DevExpress.Win.Navigation
[DefaultValue(-1)]
[DXCategory("Appearance")]
public virtual int SelectedIndex { get; set; }
<DXCategory("Appearance")>
<DefaultValue(-1)>
Public Overridable Property SelectedIndex As Integer
| Type | Default | Description |
|---|---|---|
| Int32 | -1 |
The zero-based index of the edit value in the RepositoryItemComboBox.Items collection; otherwise, -1.
|
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.
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;
}
}
Dim currentView As GridView = TryCast(sender, GridView)
Dim cmbPO As ComboBoxEdit = TryCast(currentView.ActiveEditor, ComboBoxEdit)
'.............
If cmbPO.Properties.Items.Count > 0 Then
cmbPO.SelectedIndex = 0
End If
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.
winforms-charts-use-automatic-date-time-scale-modes-of-an-axis/CS/DateTimeAggregation/Form1.cs#L30
FillFunctions();
cbMeasureUnit.SelectedIndex = 1;
}
winforms-spellchecker-enable-in-text-box/CS/Form1.cs#L40
private void cmbDictionaryType_SelectedIndexChanged(object sender, EventArgs e) {
switch (cmbDictionaryType.SelectedIndex) {
case 0:
XPO_how-to-bind-data-to-winforms-controls-using-xpbindingsource/CS/DXApplication/Form1.cs#L16
SetupLookupDataSources();
DataSourceTypeComboBox.SelectedIndex = 0;
}
winforms-charts-use-automatic-date-time-scale-modes-of-an-axis/VB/DateTimeAggregation/Form1.vb#L45
FillFunctions()
cbMeasureUnit.SelectedIndex = 1
End Sub
winforms-spellchecker-enable-in-text-box/VB/Form1.vb#L40
Private Sub cmbDictionaryType_SelectedIndexChanged(ByVal sender As Object, ByVal e As EventArgs)
Select Case cmbDictionaryType.SelectedIndex
Case 0
XPO_how-to-bind-data-to-winforms-controls-using-xpbindingsource/VB/DXApplication/Form1.vb#L15
SetupLookupDataSources()
DataSourceTypeComboBox.SelectedIndex = 0
End Sub
See Also