How to locate the node needed?

2 posts, 0 answers
  1. songsp
    songsp avatar
    9 posts
    Member since:
    Feb 2009

    Posted 16 Jun 2011 Link to this post

       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);
    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.
  2. Ivan Petrov
    Ivan Petrov avatar
    713 posts

    Posted 22 Jun 2011 Link to this post

    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.nodeFound = true;
          nodeFound = false;
        //expand the node
        //Recursively search the text in the child nodes
        this.SelectNodeInRadTreeView(nodes[i].Nodes, categoryName);
        if (this.nodeFound)
        //collapses the node

    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.
Back to Top