New to Telerik UI for WinForms? Download free 30-day trial

Data Binding

Supported Bindable Types

As an inheritor of RadListView, RadCheckedListBox extends its functionality and provides a way to bind your RadCheckedListBox check boxes to a data source. There are several types of data that CheckedMember can be bound to:

  • BooleanTrue represents ToggleState.On and False – ToggleState.Off.

  • Numeric0 represents ToggleState.Off, any other value is calculated as ToggleState.On.

  • ToggleState enumeration.

  • CheckState enumeration.

  • String – representing CheckBox ToggleState.On state with values like: "True", "On" and "T", ToggleState.Indeterminate state with value "indeterminate", ToggleState.Off state with any other value.

Information about RadListView data binding is available here: RadListView Data Binding.

Design Time

To data bind the checkboxes of RadCheckedListBox you need to set CheckedMember using the smart tag or the properties window.

WinForms RadCheckedListBox Design Time

The result is data bound CheckedListBox

WinForms RadCheckedListBox Data Bound Result

Binding Programmatically

The following example demonstrates how you can bind the control by using the CheckedMember property. This example uses the CheckState property of the business object.

1. Initially let’s create a collection of objects.

public class SimpleObject
{
    public int Id { get; set; }
    public string Name { get; set; }
    public CheckState CheckState { get; set; }
}
private IEnumerable<SimpleObject> CreateSimpleObjects()
{
    List<SimpleObject> data = new List<SimpleObject>()
        {
            new SimpleObject() { Id = 1, Name = "Item1", CheckState = CheckState.Unchecked },
            new SimpleObject() { Id = 2, Name = "Item2", CheckState = CheckState.Checked },
            new SimpleObject() { Id = 3, Name = "Item3", CheckState = CheckState.Indeterminate },
            new SimpleObject() { Id = 4, Name = "Item4", CheckState = CheckState.Unchecked },
            new SimpleObject() { Id = 5, Name = "Item5", CheckState = CheckState.Unchecked },
            new SimpleObject() { Id = 6, Name = "Item6", CheckState = CheckState.Checked }
        };
    return data;
}

2. To support three state check boxes we need to set the ThreeStateMode property:

this.radCheckedListBox1.ThreeStateMode = true;

3. And finally set programmatically the DataSource, DisplayMember, ValueMember and CheckedMember properties.

this.radCheckedListBox1.DataSource = this.CreateSimpleObjects();
this.radCheckedListBox1.DisplayMember = "Name";
this.radCheckedListBox1.ValueMember = "Id";
this.radCheckedListBox1.CheckedMember = "CheckState";

WinForms RadCheckedListBox Programmatically DataSource DisplayMember ValueMember CheckedMember