Skip to main content
A newer version of this page is available. .

BaseCheckedListBoxControl.CheckMember Property

Gets or sets the name of the data source field that provides check states for listbox items. This property is not supported when listbox items are rendered based on Item Templates

Namespace: DevExpress.XtraEditors

Assembly: DevExpress.XtraEditors.v18.2.dll

Declaration

[DefaultValue("")]
[DXCategory("Data")]
public virtual string CheckMember { get; set; }

Property Value

Type Default Description
String String.Empty

A string value specifying a field name in the data source.

Remarks

This property is in effect when a list box control is bound to a data source via the BaseListBoxControl.DataSource property and listbox items are painted in regular paint mode (Item Templates are not used).

Use the CheckMember property to specify the field whose values specify item check states. Typically, the field specified by the CheckMember property should be of the Boolean or Nullable<Boolean> type. If the field is of another type, you can convert it to the Boolean or Nullable<Boolean> type with the BaseCheckedListBoxControl.ConvertCheckValue event.

When an item’s check state is changed, a corresponding field value in the data source is changed as well.

To get the item check states, use the BaseCheckedListBoxControl.GetItemCheckState method.

Example

The following code demonstrates how you can bind the CheckedListBoxControl to a data source and obtain item captions and item check states from corresponding data source fields.

The BaseListBoxControl can be bound to a data source using the BaseListBoxControl.DataSource property. In this example, the data source is represented by the ArrayList object in which items are USState objects. The USState class represents a U.S. state. The class provides the LongName and ShortName properties specifying a state’s long and short name.

The long names of the states will be displayed as items in the list box, while the short names will specify list box item values. To accomplish this, the BaseListBoxControl.DisplayMember property is set to “LongName“ and the BaseListBoxControl.ValueMember property is set to “ShortName“.

The USState class also provides the IsSelected property. This property will specify the item check states. Set the BaseCheckedListBoxControl.CheckMember property to “IsSelected“.

When the application form is initialized, check boxes of list box items are set to the states specified by the underlaying data source. Toggling a check box affects the value of the IsSelected field in the data source.

The application form also contains a text box, displayed below the CheckedListBoxControl. If an end-user selects an item in the CheckedListBoxControl, this item’s value is displayed in the text box. The BaseListBoxControl.SelectedIndexChanged event is handled for this purpose.

BaseCheckedListBoxControl.CheckValueMember

using DevExpress.XtraEditors;

namespace CheckValueMember {
    public partial class Form1 : Form {
        CheckedListBoxControl listBox1;
        TextBox textBox1;
        public Form1() {
            InitializeComponent();

            ArrayList states1 = new ArrayList();
            states1.Add(new USState("Alabama", "AL", true));
            states1.Add(new USState("Washington", "WA", false));
            states1.Add(new USState("West Virginia", "WV", false));
            states1.Add(new USState("Wisconsin", "WI", null));
            states1.Add(new USState("Wyoming", "WY", null));

            listBox1 = new CheckedListBoxControl();
            listBox1.Location = new System.Drawing.Point(10, 10);
            listBox1.Size = new System.Drawing.Size(175, 137);

            listBox1.DataSource = states1;
            listBox1.DisplayMember = "LongName";
            listBox1.ValueMember = "ShortName";
            listBox1.CheckMember = "IsSelected";

            listBox1.SelectedIndexChanged += listBox1_SelectedIndexChanged;

            textBox1 = new TextBox();
            textBox1.Location = new System.Drawing.Point(10, 157);
            textBox1.Size = new System.Drawing.Size(175, 24);

            this.Controls.AddRange(new Control[] { this.listBox1, this.textBox1 });
        }

        void listBox1_SelectedIndexChanged(object sender, EventArgs e) {
            this.textBox1.Text = this.listBox1.SelectedValue.ToString();
        }
    }
    public class USState {
        private string myShortName;
        private string myLongName;
        private bool? isSelected;

        public USState(string strLongName, string strShortName, bool? boolIsSelected) {
            this.myShortName = strShortName;
            this.myLongName = strLongName;
            this.isSelected = boolIsSelected;
        }

        public string ShortName {
            get {
                return myShortName;
            }
        }

        public string LongName {
            get {
                return myLongName;
            }
        }

        public bool? IsSelected {

            get {
                return isSelected;
            }
            set {
                isSelected = value;
            }
        }

    }
}
See Also