开发者

How to sort list on base of checkBoxes

I want to sort array List of check boxes on base of check and unchecked status of controls checked check boxes will come first and unchecked checked b开发者_如何学运维oxes will come later in list. Then I shall add this to panel. How is this possible?


Put the CheckBoxes in a generic list and use its Sort method.

List<CheckBox> checkBoxes = GetCheckBoxes();

// Unchecked CheckBoxes first
checkBoxes.Sort((firstCheckBox, secondCheckBox) => return firstCheckBox.Checked ? +1 : -1);

// Checked CheckBoxes first
checkBoxes.Sort((firstCheckBox, secondCheckBox) => return firstCheckBox.Checked ? -1 : +1);


You can instead use a generic List of checkbox and sort it like below:

List<CheckBox> ar;
        ar.Sort(c => c.Checked);

Make sure to initialize the list ...

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜