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

converting standard treeView control

3 Answers 82 Views
TreeView
This is a migrated thread and some comments may be shown as answers.
Christian
Top achievements
Rank 1
Christian asked on 27 May 2008, 02:55 PM
Hello

the standard treeView control has classes such as "TreeNodeCollection" and "TreeNode", is there any such classes using the radTreeView?

im converting the following code to work with the rad control, it builds a tree menu from an sql database using recursive response and the treeNode and treeNodeParant standard used by MS.

it both builds the menu and checks the right to edit and access the treeNodes using a Active Directory based class along with a class to handle all the SQL database access.

public

partial class menul : System.Web.UI.UserControl
{
protected void Page_PreRender(object sender, EventArgs e)
{
if (!IsPostBack)
{
dsLocal.RightsDataTable dtSeed = new dsLocal.RightsDataTable();
dsLocal.RightsRow dr = dtSeed.NewRightsRow();
dr.MenuID = -1;
dr.AdGroup =
sesvar.not_authenticated;
dr.Hide =
false;
dr.Write =
false;
dtSeed.Rows.Add(dr);
TreeNodeCollection tc = dataAccess.getNodes(-1, Session.SessionID, dtSeed, null, 0);
treeMenu1.Nodes.Clear();
foreach (TreeNode tn in tc)
{
treeMenu1.Nodes.Add(tn);
}

tc =
dataAccess.getNodes(-2, Session.SessionID, dtSeed, null, 0);
treeMenu2.Nodes.Clear();
foreach (TreeNode tn in tc)
{
treeMenu2.Nodes.Add(tn);
}

tc =
dataAccess.getNodes(-3, Session.SessionID, dtSeed, null, 0);
treeMenu3.Nodes.Clear();
foreach (TreeNode tn in tc)
{
treeMenu3.Nodes.Add(tn);
}

if
(Session[sesvar.pageID] != null)
{
TreeNode foundNode = FindPageID(treeMeny1, (int)Session[sesvar.pageID]);
foundNode = FindPageID(treeMenu2, (
int)Session[sesvar.pageID]);
foundNode = FindPageID(treeMenu3, (
int)Session[sesvar.pageID]);
}
}
}

private TreeNode FindPageID(TreeView Tree, int PageID)
{
foreach (TreeNode nod in Tree.Nodes)
{
int testID = 0;
if (int.TryParse(nod.Value, out testID) && testID == PageID)
{
nod.Select();
return nod;
}
else
{
TreeNode tmpNode = FindPageID(nod, PageID);
if (tmpNode != null)
{
nod.Expand();
return tmpNode;
}
}

}

return null;
}

private
TreeNode FindPageID(TreeNode Tree, int PageID)
{
foreach (TreeNode nod in Tree.ChildNodes)
{
int testID = 0;

if (int.TryParse(nod.Value, out testID) && testID == PageID)
{
nod.Select();
return nod;
}

else
{
TreeNode tmpNode = FindPageID(nod, PageID);
if (tmpNode != null)
{
nod.Expand();
return tmpNode;
}
}
}
return null;
}
}


Any help re-doing this code snippet to be handled by the radTreeview would be appriciated.

Thanks in advance
Christian Persson
IT-Consultant - Netred AB
Sweden

3 Answers, 1 is accepted

Sort by
0
Erjan Gavalji
Telerik team
answered on 27 May 2008, 03:31 PM
Hi Christian,

RadTreeView has a Nodes property, which is of type RadTreeNodeCollection (similar to the ASP.NET TreeView). Basically using RadTreeView is similar to using ASP.NET TreeView. The code you sent us has an issue, which might cause RadTreeView to not work properly in some cases. It is the following:

RadTreeView is constructed in a Page_PreRender event handler. RadControls for ASP.NET Ajax are IScriptControls, which benefit of ScriptManager. As the ScriptManager control registers its scripts in a Page_PreRender handler too, the RadTreeView client-side code might not be executed. You might try using an OnPreRender override instead.
I hope this helps.

Kind regards,
Erjan Gavalji
the Telerik team

Instantly find answers to your questions at the new Telerik Support Center
0
Christian
Top achievements
Rank 1
answered on 27 May 2008, 05:48 PM

all i get is:

Line 25:             RadTreeView1.Nodes tc = dataAccess.getNodes(-1, Session.SessionID, dtSeed, null, 0);


Compiler Error Message: CS0118: 'menul.RadTreeView1' is a 'field' but is used like a 'type'


also, the private/public class decliration dont have the radtreeview substitute for TreeNode or TreeView below.

private

TreeNode FindPageID(TreeView Tree, int PageID)


any ideas?

0
Erjan Gavalji
Telerik team
answered on 28 May 2008, 08:16 AM
Hi Christian,

As the compiler error message notes, you're trying to use the Nodes property of the RadTreeView object as a method. The correct code would be similar to:

for (int i =0; i<5; i++)
{
    RadTreeNode newNode = new RadTreeNode("node" + i.ToString());
    RadTreeView1.Nodes.Add(newNode);
}

Please, check the Dynamic Creation example, demonstrating the programmatic population of the RadTreeView object with nodes.

I hope this helps.

Kind regards,
Erjan Gavalji
the Telerik team

Instantly find answers to your questions at the new Telerik Support Center
Tags
TreeView
Asked by
Christian
Top achievements
Rank 1
Answers by
Erjan Gavalji
Telerik team
Christian
Top achievements
Rank 1
Share this question
or