Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 497745
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T05:48:40+00:00 2026-05-13T05:48:40+00:00

This is the same as how most apps behave. I thought TreeView worked like

  • 0

This is the same as how most apps behave. I thought TreeView worked like that by default.

Is there a way to do this, or do I have to get all the children of a TreeNode that’s checked and check them myself?

This is winforms.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-13T05:48:40+00:00Added an answer on May 13, 2026 at 5:48 am

    You need to do it yourself, which on the other hand is not very hard:

    private void TreeView_AfterCheck(object sender, TreeViewEventArgs e)
    {
        SetChildrenChecked(e.Node, e.Node.Checked);
    }
    
    private void SetChildrenChecked(TreeNode treeNode, bool checkedState)
    {
        foreach (TreeNode item in treeNode.Nodes)
        {
            item.Checked = checkedState;
        }
    }
    

    This takes care of both checking and unchecking all children (regardless of how many levels down there may be child nodes).

    Update
    Expanded code sample that will also check/uncheck parent node if all of its child nodes are checked or unchecked manually (not thoroughly tested, could probably be done more elegantly):

    private void TreeView_AfterCheck(object sender, TreeViewEventArgs e)
    {
        SetChildrenChecked(e.Node, e.Node.Checked);
    
        if (e.Node.Parent != null)
        {
            bool setParentChecked = true;
            foreach (TreeNode node in e.Node.Parent.Nodes)
            {
                if (node.Checked != e.Node.Checked)
                {
                    setParentChecked = false;
                    break;
                }
            }
            if (setParentChecked)
            {
                e.Node.Parent.Checked = e.Node.Checked;
            }
        }
    }
    
    private void SetChildrenChecked(TreeNode treeNode, bool checkedState)
    {
        foreach (TreeNode item in treeNode.Nodes)
        {
            if (item.Checked != checkedState)
            {
                item.Checked = checkedState;
            }
        }
    }
    

    The if-block that is added in the SetChildrenChecked method will prevent a StackOverflowException in the case where you check a node with child nodes, they get checked, and when the last one is checked the parent (the one you clicked on) gets cecked and triggers the AfterCheck event again (which surprises me a bit; I would not expect the event to be raised when the Checked property value does not change but rather just gets assigned the same value it already had, but then again the event is called AfterCheck, not AfterCheckedChanged).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 269k
  • Answers 269k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer You can use polygon in base graphics, for instance x… May 13, 2026 at 1:23 pm
  • Editorial Team
    Editorial Team added an answer You shouldn't need to escape anything except the - character… May 13, 2026 at 1:23 pm
  • Editorial Team
    Editorial Team added an answer It's ugly, but you can do it with unions like… May 13, 2026 at 1:23 pm

Related Questions

In short: How to reliably discover a server running somewhere on a (presumably multi-segmented)
Short version: Is there a simple, built-in way to identify the calling view in
I have been trying to make the NLTK (Natural Language Toolkit) work on the
I don't know how authoritative this is but I found this: http://www.sqlite.org/cvstrac/wiki?p=PerformanceConsiderations and it
I need to find out whether my apps are being flagged as viruses by

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.