Reputation: 15983
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 boxes will come later in list. Then I shall add this to panel. How is this possible?
Upvotes: 0
Views: 1226
Reputation: 14784
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);
Upvotes: 1
Reputation: 2763
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 ...
Upvotes: 0