check list box rule

50 Views Asked by At

I will have several checklist box in my project and all of them shall have the same behavior. How can I solve this so I don't need to add the following code for all CLB?

        private void clbFieldprob_ItemCheck(object sender, ItemCheckEventArgs e)
        {
            for (int ix = 0; ix < clbFieldprob.Items.Count; ++ix)
                if (ix != e.Index) clbFieldprob.SetItemChecked(ix, false);
            clbFieldprob.ClearSelected();
        }
1

There are 1 best solutions below

1
Jiale Xue - MSFT On

Just like this.

private void demo_ItemCheck(Object sender, ItemCheckEventArgs e) {
    var sd = (CheckedListBox)sender;
    for (int ix = 0; ix < sd.Items.Count; ++ix)
        if (ix != e.Index) sd.SetItemChecked(ix, false);
    sd.ClearSelected();
}

Then select the control and select in the lightning(Execute for each CLB):

enter image description here

You can see three CLBs and three references in the demo.

enter image description here enter image description here