Check all checkboxes in checkboxlist with one click using c#

后端 未结 6 840
傲寒
傲寒 2021-02-03 22:46

I want to have a button that once clicked, it will select all checkboxes in my checklistbox. I\'ve search the possible answers but I always see examples for asp.net and javascri

6条回答
  •  长发绾君心
    2021-02-03 23:17

    After arriving at this question multiple times, I have decided I will solve it for myself once and for all, with an extension method.

    public static class Extensions
    {
        public static void CheckAll(this CheckedListBox checkedListBox, bool check)
        {
            for (int i = 0; i < checkedListBox.Items.Count; i++)
                checkedListBox.SetItemChecked(i, check);
        }
    }
    
    MyCheckedListBox.CheckAll(true);
    

提交回复
热议问题