treeview checked nodes

2019-03-05 04:30发布

I have used the treeview control in my C# windows application. In that i have a few parent nodes and there child nodes. i have set the ShowCheckboxes properties as ALL. So if the ckeck box of a parent node or child node is checked how can i get the no. of checked nodes.In the foreach loop what code should i use? Please help me.

标签: c# treeview
1条回答
放我归山
2楼-- · 2019-03-05 05:09

Use recursion. Here's some psuedo code:

int GetCount(Node n)
{
  int ret = 0;
  foreach (Node child in n.Nodes)
  {
    ret += GetCount(child);
  }

  return ret + (n.IsChecked() ? 1 : 0);
}
查看更多
登录 后发表回答