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 ...
精彩评论