0

I have a question regarding this post.

I have a treeview which is filled from database. I hide checkboxes which are not checked using this code:

for (int i = 0; i < _adminTv.Nodes.Count; i++)
{
    HideChecks(_adminTv.Nodes[i]);
}

private void HideChecks(TreeNode tn)
{
    if (!tn.Checked)
    {
        tn.SetIsCheckBoxVisible(false);
    }
    for (int i = 0; i < tn.Nodes.Count; i++)
    {
        HideChecks(tn.Nodes[i]);
    }
}

I want to refill this tree with a new db query and keep the invisible checkboxes invisible. Also I want to uncheck all checked nodes. So I used this code:

for (int i = 0; i < _adminTv.Nodes.Count; i++)
{
    UncheckTreeView(_adminTv.Nodes[i]);
}

private void UncheckTreeView(TreeNode tn)
{
    if (tn.Checked)
    {
        tn.Checked = false;
    }

    if (!tn.IsCheckBoxVisible())
    {
        tn.SetIsCheckBoxVisible(false);
    }

    for (int i = 0; i < tn.Nodes.Count; i++)
    {
        UncheckTreeView(tn.Nodes[i]);
    }
}

But although before calling this method the invisible nodes are indeed invisible (I tested it), in the UncheckTreeView method, the second If which checked whether the node is visible or not, is always false.

Any solution?

Community
  • 1
  • 1
Narges
  • 65
  • 2
  • 10

0 Answers0