0

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?

2
Contributors
1
Reply
2
Views
7 Years
Discussion Span
Last Post by Geekitygeek
0

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
        }
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.