RepositoryItemComboBox.Items Property
Provides access to the collection of items displayed in the editor’s dropdown.
Namespace: DevExpress.XtraEditors.Repository
Assembly: DevExpress.XtraEditors.v18.2.dll
Declaration
Property Value
Type | Description |
---|---|
ComboBoxItemCollection | The collection of items displayed by the editor. |
Remarks
The Items collection stores items displayed in the editor’s dropdown.
Elements in the Items collection can be of any type. The elements’ text representation is specified by their ToString() methods.
comboBoxEdit1.Properties.Items.Add("Red");
comboBoxEdit1.Properties.Items.Add("Yellow");
comboBoxEdit1.Properties.Items.Add("Green");
comboBoxEdit2.Properties.Items.Add(Color.Black);
comboBoxEdit2.Properties.Items.Add(Color.White);
Person p1 = new Person() { Name = "Walter" };
Person p2 = new Person() { Name = "Margaret" };
Person p3 = new Person() { Name = "Janet" };
comboBoxEdit3.Properties.Items.Add(p1);
comboBoxEdit3.Properties.Items.Add(p2);
comboBoxEdit3.Properties.Items.Add(p3);
class Person {
public string Name { get; set; }
public override string ToString() {
return Name;
}
}
Note
The editor’s items must be unique objects.
When an end-user selects a row in the dropdown, the editor assigns a corresponding item from the Items collection to the ComboBoxEdit.SelectedItem property.
To select a specific item, you can use the following approaches:
- Assign the target item’s index to the ComboBoxEdit.SelectedIndex property.
- Assign the target item to the ComboBoxEdit.SelectedItem property.
- Assign the target item to the editor’s ComboBoxEdit.EditValue property.
comboBoxEdit1.SelectedIndex = 1;
comboBoxEdit2.SelectedItem = Color.White;
comboBoxEdit3.EditValue = p3;
At design time, you can populate the Items collection with string elements in the Visual Studio Property Grid. Other item types can only be added in code.
Example
The following code creates a combo box editor and adds three items to the item collection. Each item in the example is a PersonInfo class object, which stores a person’s first and last names.
The ComboBoxItemCollection.BeginUpdate and ComboBoxItemCollection.EndUpdate methods are called to prevent excessive updates when the item collection is changed (three items are added).
The BaseListBoxControl.SelectedIndex property is set to -1 for demonstration purposes (the property is set to -1 by default). This ensures that no item is currently selected in the combo box.
ComboBoxEdit combo = new ComboBoxEdit();
ComboBoxItemCollection coll = combo.Properties.Items;
coll.BeginUpdate();
try {
coll.Add(new PersonInfo("Sven", "Petersen"));
coll.Add(new PersonInfo("Cheryl", "Saylor"));
coll.Add(new PersonInfo("Dirk", "Luchte"));
}
finally {
coll.EndUpdate();
}
combo.SelectedIndex = -1;
Controls.Add(combo);
//...
public class PersonInfo {
private string _firstName;
private string _lastName;
public PersonInfo(string firstName, string lastName) {
_firstName = firstName;
_lastName = lastName;
}
public override string ToString() {
return _firstName + " " + _lastName;
}
}
Related GitHub Examples
The following code snippets (auto-collected from DevExpress Examples) contain references to the Items 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.