Back to Devexpress

BaseCheckedListBoxControl.Items Property

windowsforms-devexpress-dot-xtraeditors-dot-basecheckedlistboxcontrol-a48a30df.md

latest6.7 KB
Original Source

BaseCheckedListBoxControl.Items Property

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

Namespace : DevExpress.XtraEditors

Assembly : DevExpress.XtraEditors.v25.2.dll

NuGet Package : DevExpress.Win.Navigation

Declaration

csharp
[DXCategory("Data")]
public CheckedListBoxItemCollection Items { get; }
vb
<DXCategory("Data")>
Public ReadOnly Property Items As CheckedListBoxItemCollection

Property Value

TypeDescription
CheckedListBoxItemCollection

A CheckedListBoxItemCollection object representing the items collection displayed within the CheckedListBoxControl.

|

Remarks

In unbound mode, use the Items property to get the item collection stored by the checked list box. You can add, remove and access individual items using index notation. Each item in the collection is represented by the CheckedListBoxItem object.

You can also access the checked indexes and items collections via the BaseCheckedListBoxControl.CheckedIndices and BaseCheckedListBoxControl.CheckedItems properties respectively.

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. To get and set an item’s check state, use the BaseCheckedListBoxControl.GetItemChecked, BaseCheckedListBoxControl.GetItemCheckState, BaseCheckedListBoxControl.SetItemChecked and BaseCheckedListBoxControl.SetItemCheckState methods.

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

Example

The following sample code demonstrates how to create and populate a CheckedListBoxControl at runtime. The image below illustrates the control’s look & feel after sample code execution.

csharp
using DevExpress.XtraEditors;
using DevExpress.XtraEditors.Controls;
// ...
CheckedListBoxItem[] items = {
                                 new CheckedListBoxItem("January", false),
                                 new CheckedListBoxItem("February", false),
                                 new CheckedListBoxItem("March", true),
                                 new CheckedListBoxItem("April", false),
                                 new CheckedListBoxItem("May", false),
                                 new CheckedListBoxItem("June", true),
                                 new CheckedListBoxItem("July", true),
                                 new CheckedListBoxItem("August", false),
                                 new CheckedListBoxItem("September", false),
                                 new CheckedListBoxItem("October", false),
                                 new CheckedListBoxItem("November", false),
                                 new CheckedListBoxItem("December", false)
                              };
private void CreateCheckedListBoxControl(CheckedListBoxItem[] items){
   CheckedListBoxControl checkedListBoxControl = new CheckedListBoxControl();
   Controls.Add(checkedListBoxControl);
   checkedListBoxControl.Left = 20;
   checkedListBoxControl.Top = 20;
   checkedListBoxControl.Width = 200;
   checkedListBoxControl.Height = 150;
   checkedListBoxControl.Items.AddRange(items);
}
// ...
CreateCheckedListBoxControl(items);
vb
Imports DevExpress.XtraEditors
Imports DevExpress.XtraEditors.Controls
' ...
Dim items() As CheckedListBoxItem = { _
  New CheckedListBoxItem("January", False), New CheckedListBoxItem("February", False), _
  New CheckedListBoxItem("March", True), New CheckedListBoxItem("April", False), _
  New CheckedListBoxItem("May", False), New CheckedListBoxItem("June", True), _
  New CheckedListBoxItem("July", True), New CheckedListBoxItem("August", False), _
  New CheckedListBoxItem("September", False), New CheckedListBoxItem("October", False), _
  New CheckedListBoxItem("November", False), New CheckedListBoxItem("December", False)}
Private Sub CreateCheckedListBoxControl(ByVal items() As CheckedListBoxItem)
   Dim checkedListBoxControl As New CheckedListBoxControl()
   Controls.Add(checkedListBoxControl)
   checkedListBoxControl.Left = 20
   checkedListBoxControl.Top = 20
   checkedListBoxControl.Width = 200
   checkedListBoxControl.Height = 150
   checkedListBoxControl.Items.AddRange(items)
End Sub
' ...
CreateCheckedListBoxControl(items)

See Also

ItemCount

CheckedIndices

CheckedItems

AddEnum

BaseCheckedListBoxControl Class

BaseCheckedListBoxControl Members

DevExpress.XtraEditors Namespace