I have a tree view with checkboxes in C #, I want that when a user checks one node, all nodes that are on the levels below are automatically checked. Does anyone know how to do this without running a recorsive fnction on the whole tree every time the user checks for some node?
thank
// this function returns treeView.
public TreeView GetTreeView()
{
getSubject();
foreach (Subject subject in subjects)
{
if (subject.subjestId == subject.parentSubject)
{
TreeNode node = new TreeNode(subject.subjectString, subject.subjestId, subject.subjestId);
addChild(node, subject.subjestId);
tv.Nodes.Add(node);
}
}
return tv;
}
private void addChild(TreeNode node, int parentId)
{
foreach (Subject subject in subjects)
{
if (subject.parentSubject == parentId && subject.parentSubject != subject.subjestId)
{
TreeNode childNode = new TreeNode(subject.subjectString, subject.subjestId, subject.subjestId);
addChild(childNode, subject.subjestId);
node.Nodes.Add(childNode);
}
}
}
source
share