all groups > dotnet general > may 2006 >
You're in the

dotnet general

group:

populating treeview


Re: populating treeview gmiley
5/31/2006 9:19:39 AM
dotnet general:
I would suggest creating possibly a class and two methods.

The class would basically represent each of your nodes we can call it
HtmlTreeNode probably with a ChildNodes property which holds a
collection of other HtmlTreeNodes and a ToHtml() method to create the
html representation of the contained data.

This could look like:

public class HtmlTreeNode
{
HtmlTreeNode[] _childNodes;
public HtmlTreeNode()
{
_childNodes = new HtmlTreeNode[];
}
public HtmlTreeNode[] ChildNodes
{
get { return _childNodes; }
set { _childNodes = value; }
}
public string ToHtml()
{
// This would create the Html output of this node, and its ChildNodes
}
}

Then for the other methods (which you could build into the class if you
want) - the first method would be something like:

HtmlTreeNode[] GetRootNodes()
{
//...
}

The second would be:

HtmlTreeNode[] GetChildNodes()
{
//...
}

The GetChildNodes() could recursively call itself to get all of the
subsequent children all the way down.

Sorry that this is in C# but you should be able to get the basic idea I
hope. If not let me know and I can try to redo it in VB, I just think
faster in C# since that's about all I use these days. =)

Hope that helps.

[quoted text, click to view]
populating treeview Mike
5/31/2006 7:55:07 PM
Hi all,

I have a dataset that contains following records:

id ref_id level
--------------------------------------
A - 0
A1 A 1
A2 A 1
A3 A 1
A11 A1 2
A12 A1 2
A21 A2 2
A31 A3 2
A211 A21 3

The column 'ref_id' is supposed to be the parent/referrer of column 'id'
That means:
A refers A1,A2 and A3
A1 refers A11,A12
and so on.

What I want to achieve is to present the above dataset using a treeview =
in
an ASP.NET 2.0 (VB) page, so it will displays like this:

[+] A
[+] A1
A11
A12
[+] A2
[+] A21
A211
[+] A3
A31

Can somebody please show me how to do this?

Many thanks in advance,
Re: populating treeview Mike
6/2/2006 12:00:00 AM
Hi there,

Thanks for the suggestion. I'll try it out, and come back to you with the
results.
Anyway, thanks a lot. I appreciate it.

Regards,
Mike

[quoted text, click to view]

AddThis Social Bookmark Button