Skip to main content

ListBoxControl.Items Property

Accesses the item collection, when the control is not bound to a data source.

Namespace: DevExpress.XtraEditors

Assembly: DevExpress.XtraEditors.v24.1.dll

NuGet Package: DevExpress.Win.Navigation

Declaration

[DXCategory("Data")]
public virtual ListBoxItemCollection Items { get; }

Property Value

Type Description
ListBoxItemCollection

A ListBoxItemCollection object representing items within the list box control.

Remarks

When the ListBox 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.

Use the ItemCount property to get the number of items in the ListBox control in bound and unbound modes.

Example

The code below uses an array of strings to populate the Items collection.

// Initialize an array of strings.
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 a data source is assigned to the ListBoxControl.
if (listBoxControl1.DataSource == null)
   // Add items to the ListBoxControl.
   listBoxControl1.Items.AddRange(myColors);
See Also