AdamMc331
AdamMc331

Reputation: 16690

How to set CheckedListBox items to checked by default

Is there an option in Visual Studio to set all items in a CheckedListBox to checked by default? By this I mean I would like all items to be checked upon start up, and the user can unselect items as needed.

If not, is my only option to set all items to checked programatically inside the constructor?

Upvotes: 7

Views: 22486

Answers (3)

Bhavik Shah
Bhavik Shah

Reputation: 1

try this i have used in VB.net

At the time of adding Items in CheckedListBox use below code :

For i As Integer = 0 To Dt.Rows.Count - 1
    CLB_FolderList.Items.Add(Dt.Rows(i)("Source_FolderName").ToString(),True)
Next

Upvotes: 0

Rafik Bari
Rafik Bari

Reputation: 5037

 private void Form1_Load(object sender, EventArgs e)
    {
       for (int i = 0; i < checkedListBox.Items.Count; i++)
       {
         checkedListBox.SetItemChecked(i, true);
       }  

    }

Upvotes: 1

Sriram Sakthivel
Sriram Sakthivel

Reputation: 73472

You can do it programmatically after populating the Items

for (int i = 0; i < checkedListBox.Items.Count; i++)
{
    checkedListBox.SetItemChecked(i, true);
}

Upvotes: 11

Related Questions