Use checkbox to select items in a listbox

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Im very new to coding and I was wondering if anyone could please tell me how
to select all the items in a listbox when a checkbox is checked, and then
when the checkbox is unchecked to unselected the items in the listbox. Here
is the event I would like to put this into.

private void chkSelectAll_CheckedChanged(object sender,
System.EventArgs e)
{

}

Thank you for any help you can give me
 
Hi Stephen,

private void chkSelectAll_CheckedChanged(object sender,
System.EventArgs e)
{
for(int i = 0; i < myListBox.Items.Count; i++)
{
myListBox.SetSelected(i, chkSelectAll.Checked);
}
}

Note that unless the ListBox' SelectionMode is set to one of the multi modes you will only see the last item selected.
 
Back
Top