0

In WPF, C# application, I have 4 checkboxes,

  1. select all

  2. team

  3. personal

  4. subteam.

As usual, 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.

2 Answers 2

1

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.

Sign up to request clarification or add additional context in comments.

1 Comment

ya.. currently its only 4 chkboxes, but if it increases.. its quite complex to maintain right.. any other ideas on this? Thanks Ramm
0

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.