tags:

views:

516

answers:

2

Hi,

In WPF, C# application, I have 4 checkboxes, 1. select all 2. team 3. personal 4. subteam. Asusual, if choose option 1, it selects all the checkboxes and when it is unchecked it unchecks all.. this is working fine for me..

But when I click select all (all will be checked,....) and if I uncheck any of the other 3, then selectall should be unchecked..

 public void AllChartsSelected()
    {
        if (_view.SelectAllChartsCheckBox)
        {
            boolSelectAll = true;

            _view.TeamCheckBox = true;
            _view.PersonalCheckBox = true;
            _view.SubTeamCheckBox = true;

        }
        else
        {
 boolSelectAll = false;
            _view.TeamCheckBox = false;
            _view.PersonalCheckBox = false;
            _view.SubTeamCheckBox = false;


        }
}

after this, I couldn't get it right for the unchecking of a checkbox should uncheck the select all checkbox too...

Please help. Thanks Ramm

+1  A: 

That's easy. In the event handlers of the 2nd 3rd & 4th checkboxes, check if all of them is selected, and set the checkstate of the first one accordingly.

erelender
ya.. currently its only 4 chkboxes, but if it increases.. its quite complex to maintain right..any other ideas on this?ThanksRamm
Aditya
A: 

The _view object is a ViewModel object (not a control), am I right? If so, then you should better subscribe somewhere to changes of those properties and set the SelectAll property in the handler accordingly. When either property changes your SelectAll property will stay up to date.

If _view is a View (a control), then you've probably made a typo here ('.IsChecked' missing everywhere?) and then it's a really bad practice to do the checking/unchecking in the code. You should bind the checkboxes to some properties.

arconaut