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

  • Home
  • SEARCH
  • 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 9117039
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T04:48:54+00:00 2026-06-17T04:48:54+00:00

I have a TreeView populated from database with lots of node, and each node

  • 0

I have a TreeView populated from database with lots of node, and each node may have some children and there is no fixed role like 2 depthes, it may be very deep.

Imagine that the TreeView CheckBoxes are RadioButtons, I want my TreeView just to have one checked node at a time. I have tried AfterCheck and BeforeCheck events but they fall into forever loop, what can I do?

I want to keep my checked node CHECKED and uncheck all other nodes but I can’t. Waiting for your smart points. Thanks.

Here’s the code I have tried but ended up with a StackOverFlow exception, and I thought maybe it’s saying go and check it on StackOverflow 😀

private void tvDepartments_AfterCheck(object sender, TreeViewEventArgs) 
{
   List<TreeNode> nodes = new List<TreeNode>();
   if (rdSubDepartments.Checked)
       CheckSubNodes(e.Node, e.Node.Checked);
   else if (rdSingleDepartment.Checked)
   {
       foreach (TreeNode node in tvDepartments.Nodes)
       {
           if (node != e.Node)
               node.Checked = false;
       }
   }
}


public void CheckSubNodes(TreeNode root, bool checkState)
{
    foreach (TreeNode node in root.Nodes)
    {
        node.Checked = checkState;
        if (node.Nodes.Count > 0)
            CheckSubNodes(node, checkState);
    }
}
  • 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-06-17T04:48:55+00:00Added an answer on June 17, 2026 at 4:48 am

    Mahdi here is what this should look like Ref from TreeView.AfterCheck Event

    // Updates all child tree nodes recursively. 
    private void CheckAllChildNodes(TreeNode treeNode, bool nodeChecked)
    {
       foreach(TreeNode node in treeNode.Nodes)
       {
          node.Checked = nodeChecked;
          if(node.Nodes.Count > 0)
          {
             // If the current node has child nodes, call the CheckAllChildsNodes method recursively. 
             this.CheckAllChildNodes(node, nodeChecked);
          }
       }
    }
    
    // NOTE   This code can be added to the BeforeCheck event handler instead of the AfterCheck event. 
    // After a tree node's Checked property is changed, all its child nodes are updated to the same value. 
    private void node_AfterCheck(object sender, TreeViewEventArgs e)
    {
       // The code only executes if the user caused the checked state to change. 
       if(e.Action != TreeViewAction.Unknown)
       {
          if(e.Node.Nodes.Count > 0)
          {
             /* Calls the CheckAllChildNodes method, passing in the current 
             Checked value of the TreeNode whose checked state changed. */ 
             this.CheckAllChildNodes(e.Node, e.Node.Checked);
          }
       }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a treeview which contains, per node, a key and text. However, there
I have a treeView , and i want to know if some node can
I have a TreeView which will be populated with some Nodes. The problem is,
I have a Treeview. This treeview gets populated client side with children in javascript
I want to make a dynamic populated treeview from mysql database in PHP. I
I have a TreeView menu populated from a SiteMapDataSource. The TreeView defaults to all
I Have a treeView Already populated (in vb.net) and would Like to move all
I have TreeView Populating from Database And I am Trying to detect the user
I have a TreeView that launches a new window when each of its TreeViewItems
I have a treeview that is bound to a collection and each item in

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.