RepositoryItemComboBox.Items Property
Provides access to the collection of items displayed in the editor’s dropdown.
Namespace: DevExpress.XtraEditors.Repository
Assembly: DevExpress.XtraEditors.v24.1.dll
NuGet Package: DevExpress.Win.Navigation
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: Set ComboBox Bar Item Value in Ribbon
using System;
using DevExpress.XtraBars;
using DevExpress.XtraEditors.Repository;
public partial class Form1 : DevExpress.XtraBars.Ribbon.RibbonForm {
BarEditItem barEditItemComboBox;
public Form1() {
InitializeComponent();
// Creates a ComboBox repository item.
RepositoryItemComboBox comboBoxSettings = new RepositoryItemComboBox();
// Adds items to the 'Items' colelction.
comboBoxSettings.Items.AddRange(new string[] { "Item A", "Item B", "Item C" });
// Creates and initializes a BarEditItem.
barEditItemComboBox = new BarEditItem(ribbonControl1.Manager, comboBoxSettings);
// Specifies the width of the ComboBox.
barEditItemComboBox.EditWidth = 140;
// Adds the BarEditItem to a Ribbon group.
ribbonControl1.Pages[0].Groups[0].ItemLinks.Add(barEditItemComboBox);
}
private void Form1_Load(object sender, EventArgs e) {
// Sets the editor's value.
barEditItemComboBox.EditValue = "Item B";
}
}
Example
The following code creates a ComboBoxEdit control, and adds three items to the control. Items are PersonInfo class objects. Each item stores a person’s first and last names.
The example uses the ComboBoxItemCollection.BeginUpdate and ComboBoxItemCollection.EndUpdate methods to prevent excessive updates when the item collection is changed.
The ComboBoxEdit.SelectedIndex property is set to -1
for demonstration purposes (the property is initially set to -1
). This ensures that no item is selected on application startup.
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.