我创建了一个动态创建的父视图和子视图的树视图。还启用了checkbox属性true.hence为每个节点设置了复选框。 问题是如何命名这些复选框,以便对于特定用户,如果值为true,则应选中复选框,否则如果值为false,则需要取消选中该复选框。 true或false值存储在db中的特定列中。
答案 0 :(得分:0)
请按照我提供的代码,它可能会从您对您的问题的理解中给出一些想法。我也提供了链接。 http://msdn.microsoft.com/en-us/library/wwc698z7(v=vs.90).aspx
private void PrintRecursive(TreeNode treeNode)
{
// Print the node.
System.Diagnostics.Debug.WriteLine(treeNode.Text);
MessageBox.Show(treeNode.Text);
// Print each node recursively.
foreach (TreeNode tn in treeNode.Nodes)
{
PrintRecursive(tn);
}
}
// Call the procedure using the TreeView.
private void CallRecursive(TreeView treeView)
{
// Print each node recursively.
TreeNodeCollection nodes = treeView.Nodes;
foreach (TreeNode n in nodes)
{
PrintRecursive(n);
}
}
答案 1 :(得分:0)
您可以通过以下代码检查选中的节点
foreach (TreeNode node in yourtreeview.Nodes)
{
if (node.Checked)
{ //here You can check here your parent nodes is checked or not
//your calculations
}
foreach (TreeNode ChildNode in node.Nodes)
{
if (ChildNode.Checked)
{ // here you can check your 2nd level nodes
}
foreach (TreeNode childofChild in ChildNode.Nodes)
{
if (childofChild.Checked)
{ here you can check your 3rd level node }
foreach (TreeNode GrandChildofChild in childofChild.Nodes)
{
if (GrandChildofChild.Checked)
{
//here you can check your fourth level node
}
}
}
}
}