Back to Devexpress

ComboBoxEdit.SelectedItem Property

windowsforms-devexpress-dot-xtraeditors-dot-comboboxedit.md

latest6.6 KB
Original Source

ComboBoxEdit.SelectedItem Property

Specifies the editor’s value.

Namespace : DevExpress.XtraEditors

Assembly : DevExpress.XtraEditors.v25.2.dll

NuGet Package : DevExpress.Win.Navigation

Declaration

csharp
[Browsable(false)]
public virtual object SelectedItem { get; set; }
vb
<Browsable(False)>
Public Overridable Property SelectedItem As Object

Property Value

TypeDescription
Object

The editor’s value.

|

Remarks

When you select an item from the dropdown, a corresponding object from the item collection is automatically assigned to SelectedItem. In addition, entering a value in the edit box changes the SelectedItem.

The SelectedItem property matches the value of the ComboBoxEdit.EditValue property. The difference between them is that you can set ComboBoxEdit.EditValue to any object, while SelectedItem can be set only to an element of the RepositoryItemComboBox.Items collection.

The ComboBoxEdit.SelectedIndex property returns the index of the SelectedItem value in the RepositoryItemComboBox.Items collection. This allows you to know whether the current editor’s value is from the dropdown list or arbitrary data.

Note : to ensure proper functionality of the editor, items in the RepositoryItemComboBox.Items collection must be unique objects.

The code sample below illustrates how to use a combo box to specify the data source for a grid.

csharp
xmlDataSet = new System.Data.DataSet("XML DataSet");
xmlDataSet.ReadXml(@".\\transportation.xml");
comboBoxEdit1.Properties.Items.AddRange(new string[] { "Drivers", "Vehicles", "Products" });

private void comboBoxEdit1_SelectedIndexChanged(object sender, EventArgs e)
{
    var combo = sender as ComboBoxEdit;
    gridControl1.DataSource = xmlDataSet.Tables[combo.SelectedItem.ToString()];

}
vb
xmlDataSet = New System.Data.DataSet("XML DataSet")
xmlDataSet.ReadXml(".\\transportation.xml")
comboBoxEdit1.Properties.Items.AddRange(New String() { "Drivers", "Vehicles", "Products" })

private void comboBoxEdit1_SelectedIndexChanged(Object sender, EventArgs e)
    Dim combo = TryCast(sender, ComboBoxEdit)
    gridControl1.DataSource = xmlDataSet.Tables(combo.SelectedItem.ToString())

The following code snippets (auto-collected from DevExpress Examples) contain references to the SelectedItem 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-scheduler-sync-with-google-calendars/CS/GCSync/Form1.cs#L53

csharp
ComboBoxEdit edit = (ComboBoxEdit)sender;
string selectedCalendarSummary = (string)edit.SelectedItem;
CalendarListEntry selectedCalendar = this.calendarList.Items.FirstOrDefault(x => x.Summary == selectedCalendarSummary);

map-for-winforms-azure-routing/CS/Form1.cs#L77

csharp
AzureTravelMode GetTravelMode() {
    return (AzureTravelMode)Enum.Parse(typeof(AzureTravelMode), (string)travelModeComboBox.SelectedItem);
}

winforms-charts-use-automatic-date-time-scale-modes-of-an-axis/CS/DateTimeAggregation/Form1.cs#L244

csharp
void ExecuteSelectedItemAction(ComboBoxEdit comboBox) {
    ComboBoxItem item = comboBox.SelectedItem as ComboBoxItem;
    if (item != null) {

winforms-scheduler-sync-with-google-calendars/VB/GCSync/Form1.vb#L56

vb
Dim edit As ComboBoxEdit = CType(sender, ComboBoxEdit)
Dim selectedCalendarSummary As String = CStr(edit.SelectedItem)
Dim selectedCalendar As CalendarListEntry = calendarList.Items.FirstOrDefault(Function(x) Equals(x.Summary, selectedCalendarSummary))

map-for-winforms-azure-routing/VB/Form1.vb#L71

vb
Private Function GetTravelMode() As AzureTravelMode
    Return CType([Enum].Parse(GetType(AzureTravelMode), CStr(travelModeComboBox.SelectedItem)), AzureTravelMode)
End Function

winforms-charts-use-automatic-date-time-scale-modes-of-an-axis/VB/DateTimeAggregation/Form1.vb#L238

vb
Private Sub ExecuteSelectedItemAction(ByVal comboBox As ComboBoxEdit)
    Dim item As ComboBoxItem = TryCast(comboBox.SelectedItem, ComboBoxItem)
    If item IsNot Nothing Then

See Also

EditValue

SelectedIndex

Items

ComboBoxEdit Class

ComboBoxEdit Members

DevExpress.XtraEditors Namespace