ListBoxControl.Items Property
Provides access to the item collection, when the control is not bound to a data source.
Namespace: DevExpress.XtraEditors
Assembly: DevExpress.XtraEditors.v18.2.dll
Declaration
Property Value
Type | Description |
---|---|
ListBoxItemCollection | A ListBoxItemCollection object representing items within the list box control. |
Remarks
When the control is not bound to a data source, use the Items property to access the control’s item collection. You can add, remove and access items using index notation. Each item is represented by the ListBoxItem object.
To improve the control’s performance while performing multiple changes on the item collection, use the ListBoxItemCollection.BeginUpdate/ListBoxItemCollection.EndUpdate methods
When the control is bound to a data source via the BaseListBoxControl.DataSource property, the Items collection is always empty. In this instance, to access particular items, use the BaseListBoxControl.GetItem method.
Example
The following sample code initializes the myColors array of strings representing system color names. Then, if no external data source is assigned to the control, the ListBoxControl‘s item collection is populated with myColors elements.
// Initialize an array of strings representing system colors names
string[] myColors = {
Color.Black.Name,
Color.Blue.Name,
Color.Brown.Name,
Color.Green.Name,
Color.Red.Name,
Color.Yellow.Name,
Color.Orange.Name
};
// Check whether an external data source is assigned to the ListBox
if (listBoxControl1.DataSource == null)
// add items to the ListBox.
listBoxControl1.Items.AddRange(myColors);
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.