In my C# Class I have a Windows Form with 4 checkBoxes and 1 listBox. Three of the checkBoxes are Ford, Chevrolet, and Cadillac; and the 4th is All.

Checking each box displays that make of car OR all cars. Unchecking each Box removes that car from the listbox. So, if you check Ford, Chevrolet, and Cadillac AND THEN unCheck Ford you would be left with only Cadillac and Chevrolet.

My problem is the ALL. When I click ALL four checkBoxes the ALL list is appended to the list of the other three and when you uncheck all (using ...items.clear()) it removes everything.

The Demo program for this project Displays ALL by itself and it seems to operate independently of the other 3. Like it is either overlaying the list OR there is another listBox of a different name but the exact same size that is only visible when the allCheckBox.Checked == true.

Is there a way to do this without a second listbox?

why not just use the 'ALL' checkChanged event to set all the other checkboxes to be checked. That way it will write the list with all the cars in it the same way as if you had manually clicked on each checkbox :)

private void chbAll_CheckedChanged(object sender, EventArgs e)
        {
            //using chbAll.Checked means that when you uncheck the All box it will deselect all the others
            chbFord.Checked = chbAll.Checked;
            chbCadillac.Checked = chbAll.Checked;
            //etc
        }
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.