Captain_Teemo
Captain_Teemo

Reputation: 29

How to select all checkbox using Itemcheck event?

Can you guys help me code if I select one of the checkboxes on the ListView section, the rest of the checkboxes should be checked.

My ListView name is lvBase and I want to used the ListView ItemCheck events.

This is my code.

private void lvBase_ItemCheck_1(object sender, ItemCheckEventArgs e)
    {
    }

enter image description here

enter image description here

enter image description here

Upvotes: 0

Views: 270

Answers (2)

Anu Viswan
Anu Viswan

Reputation: 18155

Hope I understood your question correctly, If you want to check all the checkbox in the list, you can loop through them and set Checked Property to true.

    private void lvBase_ItemChecked(object sender, ItemCheckedEventArgs e)
    {
        for (int i = 0; i < lvBase.Items.Count; i++)
        {
            lvBase.Items[i].Checked = e.Item.Checked;
        }
    }

Upvotes: 1

Moataz Ahmed Samy
Moataz Ahmed Samy

Reputation: 146

Use the following line to add an itemcheck or itemchecked event:

 this.listView1.ItemCheck += new ItemCheckEventHandler(listView1_ItemCheck);

Upvotes: 1

Related Questions