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

Select the last node in the tree

2 Answers 104 Views
TreeView
This is a migrated thread and some comments may be shown as answers.
Debashis Pyne
Top achievements
Rank 1
Debashis Pyne asked on 01 Oct 2010, 04:29 PM
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 Answers, 1 is accepted

Sort by
0
Shinu
Top achievements
Rank 2
answered on 04 Oct 2010, 07:36 AM
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.
0
Veronica
Telerik team
answered on 04 Oct 2010, 08:46 AM
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
Tags
TreeView
Asked by
Debashis Pyne
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 2
Veronica
Telerik team
Share this question
or