This is a migrated thread and some comments may be shown as answers.

[Solved] Treeview with Checkbox

2 Answers 170 Views
TreeView
This is a migrated thread and some comments may be shown as answers.
André Freitas
Top achievements
Rank 1
André Freitas asked on 03 Feb 2010, 04:42 PM
I got a treeview, where its importante to me to get the full path of id's, from the first parent, to the last child checked, but the user dont need to get in the full depth of each tree.

I tried:

 

string message = string.Empty;

 

foreach (RadTreeNode node in trvCategorization.CheckedNodes)

 

 

{
    if (node.Nodes.Count == 0)

        message += node.FullPath +

 

 

 

 

"<br/>";

 }

Label1.Text = message;

 

 


It doesnt work. Besides certain nodes have no checked nodes, these uncheked nodes are retuned by the Count. And I can get the ID path using that, theres no FullValuePath method. I cant do a node.CheckedNodes.Count too. Is there a built in method that I still dont look at, or do I need to code a recursive method to get these paths, since i can have different depths in diferente cenarios?

How do I use the format code block?

2 Answers, 1 is accepted

Sort by
0
André Freitas
Top achievements
Rank 1
answered on 03 Feb 2010, 06:11 PM

I do got a general idea, and I ll post de code here. Any tip will be appreciated.

foreach (RadTreeNode n in trvCategorization.Nodes)
   {
    if (n.Checked == true)
    {
     chkCategorizationGetFullPathValues(n);
    }
   }

protected void GetFullPathValue(RadTreeNode nodes)
  {
   foreach (RadTreeNode n in nodes.Nodes)
   {
    if (n.Checked == true)
    {
     chkCategorizationGetFullPathValues(n);
    }
    else
    {
     StringBuilder valuePath = new StringBuilder("|");

     valuePath.Append(n.Value);

     while (n.ParentNode != null)
     {
      valuePath.Insert(0, n.ParentNode.Value);
      valuePath.Insert(0, "|");

      n = n.ParentNode;
     }

     // set to a member variable here
    }
   }
  }

The only problem: usualy I do avoid member variables. is there another way to get this result?

0
Accepted
André Freitas
Top achievements
Rank 1
answered on 04 Feb 2010, 04:35 PM
Got  it working:

foreach (RadTreeNode node in trvCategorization.Nodes)
{
    if (node.Checked)
    {
        arrCategorization.Add(node.Value);
        btnSaveFindCheckedNode(node);
    }
}

protected void btnSaveFindCheckedNode(RadTreeNode nodes)
{
    foreach (RadTreeNode node in nodes.Nodes)
    {
        if (node.Checked)
        {
            btnSaveGetNodeFullValuePath(node);
            btnSaveFindCheckedNode(node);
        }
    }
}

private void btnSaveGetNodeFullValuePath(RadTreeNode node)
{
    StringBuilder fullValuePath = new StringBuilder();

    fullValuePath.Append(node.Value);

    while (node.ParentNode != null)
    {
        fullValuePath.Insert(0, node.ParentNode.Value);
        fullValuePath.Insert(node.ParentNode.Value.Length, "|");
        node = node.ParentNode;
    }

    arrCategorization.Add(fullValuePath.ToString());
}

The GetNodeFullValuePath function was created by a Telerik admin, i got it here in the forum, but I dont remember where to appropriate link it (sorry).

Tags
TreeView
Asked by
André Freitas
Top achievements
Rank 1
Answers by
André Freitas
Top achievements
Rank 1
Share this question
or