Select the last node in the tree

3 posts, 0 answers
  1. Debashis Pyne
    Debashis Pyne avatar
    66 posts
    Member since:
    Apr 2010

    Posted 01 Oct 2010 Link to this post

    Hi,

    I have a tree view bound from the database, so that by clicking on a node I can found the text and corresponding data value field.

    protected void GenerateCompanyTree()
    {
    DataTable DtCompany;
    JOMCMiddleWare.BL.CompanyStructure oCompanyStructure = new JOMCMiddleWare.BL.CompanyStructure();

    oCompanyStructure._Module_Id = oCompanyStructure._Module_Id;
    oCompanyStructure._Language_Id = Convert.ToInt32(Session[JOMCSession.__Session_Lanuage_Id]);
    oCompanyStructure._Company_Id = Convert.ToInt32(Session[JOMCSession.__Session_Company_Id]);
    DtCompany = oCompanyStructure.GetDataAllTreeViewCompanyStructure();

    if (DtCompany.Rows.Count > 0)
    {
    RadTreeViewCompany.DataSource = DtCompany;
    RadTreeViewCompany.DataTextField = "Module_Content_Text";
    RadTreeViewCompany.DataFieldID = "Company_Id";
    RadTreeViewCompany.DataFieldParentID = "Company_Parent_Id";
    RadTreeViewCompany.DataValueField = "Company_Id";
    RadTreeViewCompany.DataBind();
    RadTreeViewCompany.ExpandAllNodes();
    }
    }

    Now, I have the requirement that I have to enable only those nodes at the bottom (leaf level) only.
    Any idea, how to achieve this?

    Thanks
  2. Shinu
    Shinu avatar
    17764 posts
    Member since:
    Mar 2007

    Posted 04 Oct 2010 Link to this post

    Hello Debashis,

    One suggestion is iterating through the nodes and setting the Enablesd property based on the child node count. Add the code in OnDataBound event of treeview.

    C#:
    foreach (RadTreeNode node in RadTreeView2.GetAllNodes())
    {
        if (node.Nodes.Count != 0)
        {
            node.Enabled = false;
        }
        else
        {
            node.Enabled = true;
        }
    }



    -Shinu.
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Veronica
    Admin
    Veronica avatar
    1213 posts

    Posted 04 Oct 2010 Link to this post

    Hi Debashis Pyne,

    You can use the following javascript code to determine which node is leaf and make all nodes which have children - disabled:

    function pageLoad() {
                var tree = $find("<%= RadTreeView1.ClientID %>");
                var nodes = tree.get_allNodes();
                for (var i = 0; i < nodes.length; i++) {
                    if (nodes[i].get_nodes().get_count() != 0) {
                        nodes[i].disable();
                    }
                }
            }

    Please note that "RadTreeView1" is the ID of the RadTreeView. You should replace it with the ID of your tree.

    Hope this helps.

    Kind regards,
    Veronica Milcheva
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
Back to Top