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

How to locate the node needed?

1 Answer 31 Views
Treeview
This is a migrated thread and some comments may be shown as answers.
songsp
Top achievements
Rank 1
songsp asked on 16 Jun 2011, 03:36 PM
Hello,Telerik
   Really I meet trouble when I use Radtreeview on winform .
   My business is the order including products,and product belongs to one category,category is tree-structure.
   In the product Adding-Form,I select the category from the Category-tree is OK.
  But When I want to modify the product detail information,How can I locate the current product Category-ID among the Category Tree..
such as

             ProductDAO productDao = new ProductDAO();
            Product product = productDao.GetProductDetailByProductId(productId);
            tbxProductName.Text = product.ProductName;
            tbxProductNote.Text = product.Remark;
            tbxProductPrice.Value = product.Price.Value;
            tbxProductQuantity.Value = (decimal)product.ProductCount.Value;
            tbxUnit.Text = product.Unit;
            ProductCategory proCategory = productDao.GetCategoryByCategoryId(product.ProductCategoryID.Value);
            GotoSelectNode(proCategory.CategoryName);
My Category Tree is :

  private void InitPvProductCategoryTree()
        {
            ProductDAO proDao = new ProductDAO();

            List<ProductCategory> categorys = proDao.GetAllCategoryList("");
            tbxCategroy.DisplayMember = "CategoryName";
            this.tbxCategroy.ValueMember = "ProductCategoryID";
            this.tbxCategroy.ParentIDMember = "ParentID";
            this.tbxCategroy.DataSource = categorys;

            // this.tbxCategroy.DataMember = "Nodes";

        }


How to Implement the method of GotoSelectNode?
My Telerik version is 2010 q3

Thanks .Hope your reply.

1 Answer, 1 is accepted

Sort by
0
Ivan Petrov
Telerik team
answered on 22 Jun 2011, 09:08 AM
Hi songsp,

Thank you for writing.

You can try the following code snippet to select the category in your tree:

private void SelectNodeInRadTreeView(RadTreeNodeCollection nodes, string categoryName)
{
  for (int i = 0; i < nodes.Count; i++)
  {
    if (nodes[i].Text == categoryName)
    {
      this.radTreeView1.SelectedNode = nodes[i];
      this.radTreeView1.Select();
      this.nodeFound = true;
      return;
    }
    else
    {
      nodeFound = false;
    }
    //expand the node
    nodes[i].Expand();
    //Recursively search the text in the child nodes
    this.SelectNodeInRadTreeView(nodes[i].Nodes, categoryName);
    if (this.nodeFound)
    {
      return;
    }
    //collapses the node
    nodes[i].Collapse();
    //return;
  }
}

I hope this helps you. If you have further questions I would be glad to help. Kind regards,
Ivan Petrov
the Telerik team
Q1’11 SP1 of RadControls for WinForms is available for download; also available is the Q2'11 Roadmap for Telerik Windows Forms controls.
Tags
Treeview
Asked by
songsp
Top achievements
Rank 1
Answers by
Ivan Petrov
Telerik team
Share this question
or