开发者

How to sort list on base of checkBoxes

开发者 https://www.devze.com 2023-02-22 09:02 出处:网络
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. The

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

精彩评论

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