adding subnodes to a tree recursively

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi peeps..

Im using the TreeView control from IE COntrols to create a directory
structure, and trying to do it recursively.

The code works, but my question is simply how can I make the subdirs appear
as leaves in the Tree, rather than as new branches?

Here's the code..

private void RecurseTree(DirectoryInfo theDir, int nLevel)
{
TreeNode libraryNode = null;
DirectoryInfo[] subFolders = theDir.GetDirectories();

// populate the tree
for (int i=0; i < subFolders.Length; i++)
{
libraryNode = new TreeNode();
libraryNode.Text = subFolders.Name;
treeDocuments.Nodes.Add(libraryNode);
libraryNode = null;
RecurseTree(subFolders, nLevel+1);
}
}

Any help appreciated!

Cheers


Dan
 
Hi Dan,
Do u have a way of the possibilty of Expanding All /Collapsing All
treeviews?
let me know and thx
 
Patrick,

Try this..

private void ExpandAll()
{
for(int i=0; i < yourTree.Nodes.Count; i++)
{
yourTree.Nodes.Expanded = true;
}
}

This works for me, although there might be a simple command to do this
(haven't found one yet!). Obviously setting Expanded to false will give you a
CollapseAll function as well :)

HTH


Dan
Patrick.O.Ige said:
Hi Dan,
Do u have a way of the possibilty of Expanding All /Collapsing All
treeviews?
let me know and thx


Dan Nash said:
Hi peeps..

Im using the TreeView control from IE COntrols to create a directory
structure, and trying to do it recursively.

The code works, but my question is simply how can I make the subdirs appear
as leaves in the Tree, rather than as new branches?

Here's the code..

private void RecurseTree(DirectoryInfo theDir, int nLevel)
{
TreeNode libraryNode = null;
DirectoryInfo[] subFolders = theDir.GetDirectories();

// populate the tree
for (int i=0; i < subFolders.Length; i++)
{
libraryNode = new TreeNode();
libraryNode.Text = subFolders.Name;
treeDocuments.Nodes.Add(libraryNode);
libraryNode = null;
RecurseTree(subFolders, nLevel+1);
}
}

Any help appreciated!

Cheers


Dan

 
Don't worry about the subnodes question - I've sorted it with...

tree.Nodes.Nodes.Add()

Ta tho :)
 
Thx but i'm using the Treeview WebControl and i'm just loading my XML
the TreeNodeSrc= "Xmlfile"
Can i add the code u adviced? And where?



Dan Nash said:
Patrick,

Try this..

private void ExpandAll()
{
for(int i=0; i < yourTree.Nodes.Count; i++)
{
yourTree.Nodes.Expanded = true;
}
}

This works for me, although there might be a simple command to do this
(haven't found one yet!). Obviously setting Expanded to false will give you a
CollapseAll function as well :)

HTH


Dan
Patrick.O.Ige said:
Hi Dan,
Do u have a way of the possibilty of Expanding All /Collapsing All
treeviews?
let me know and thx


Dan Nash said:
Hi peeps..

Im using the TreeView control from IE COntrols to create a directory
structure, and trying to do it recursively.

The code works, but my question is simply how can I make the subdirs appear
as leaves in the Tree, rather than as new branches?

Here's the code..

private void RecurseTree(DirectoryInfo theDir, int nLevel)
{
TreeNode libraryNode = null;
DirectoryInfo[] subFolders = theDir.GetDirectories();

// populate the tree
for (int i=0; i < subFolders.Length; i++)
{
libraryNode = new TreeNode();
libraryNode.Text = subFolders.Name;
treeDocuments.Nodes.Add(libraryNode);
libraryNode = null;
RecurseTree(subFolders, nLevel+1);
}
}

Any help appreciated!

Cheers


Dan

 
Hi Patrick

I'm also using the WebControl and it works fine. Just add the function to
your page class in CodeBehind and call it from your Page_Load event.
Obviously it's C#, so if you're using VB you'll have to rewrite accordingly,
but haven't got VB.net, sorry!

HTH


Patrick.O.Ige said:
Thx but i'm using the Treeview WebControl and i'm just loading my XML
the TreeNodeSrc= "Xmlfile"
Can i add the code u adviced? And where?



Dan Nash said:
Patrick,

Try this..

private void ExpandAll()
{
for(int i=0; i < yourTree.Nodes.Count; i++)
{
yourTree.Nodes.Expanded = true;
}
}

This works for me, although there might be a simple command to do this
(haven't found one yet!). Obviously setting Expanded to false will give you a
CollapseAll function as well :)

HTH


Dan
Patrick.O.Ige said:
Hi Dan,
Do u have a way of the possibilty of Expanding All /Collapsing All
treeviews?
let me know and thx


Hi peeps..

Im using the TreeView control from IE COntrols to create a directory
structure, and trying to do it recursively.

The code works, but my question is simply how can I make the subdirs
appear
as leaves in the Tree, rather than as new branches?

Here's the code..

private void RecurseTree(DirectoryInfo theDir, int nLevel)
{
TreeNode libraryNode = null;
DirectoryInfo[] subFolders = theDir.GetDirectories();

// populate the tree
for (int i=0; i < subFolders.Length; i++)
{
libraryNode = new TreeNode();
libraryNode.Text = subFolders.Name;
treeDocuments.Nodes.Add(libraryNode);
libraryNode = null;
RecurseTree(subFolders, nLevel+1);
}
}

Any help appreciated!

Cheers


Dan

 
Can u give me an example of the code behind and
How i should call it from Page_load.
Thx


Dan Nash said:
Hi Patrick

I'm also using the WebControl and it works fine. Just add the function to
your page class in CodeBehind and call it from your Page_Load event.
Obviously it's C#, so if you're using VB you'll have to rewrite accordingly,
but haven't got VB.net, sorry!

HTH


Patrick.O.Ige said:
Thx but i'm using the Treeview WebControl and i'm just loading my XML
the TreeNodeSrc= "Xmlfile"
Can i add the code u adviced? And where?



Dan Nash said:
Patrick,

Try this..

private void ExpandAll()
{
for(int i=0; i < yourTree.Nodes.Count; i++)
{
yourTree.Nodes.Expanded = true;
}
}

This works for me, although there might be a simple command to do this
(haven't found one yet!). Obviously setting Expanded to false will
give
you a
CollapseAll function as well :)

HTH


Dan
:

Hi Dan,
Do u have a way of the possibilty of Expanding All /Collapsing All
treeviews?
let me know and thx


Hi peeps..

Im using the TreeView control from IE COntrols to create a directory
structure, and trying to do it recursively.

The code works, but my question is simply how can I make the subdirs
appear
as leaves in the Tree, rather than as new branches?

Here's the code..

private void RecurseTree(DirectoryInfo theDir, int nLevel)
{
TreeNode libraryNode = null;
DirectoryInfo[] subFolders = theDir.GetDirectories();

// populate the tree
for (int i=0; i < subFolders.Length; i++)
{
libraryNode = new TreeNode();
libraryNode.Text = subFolders.Name;
treeDocuments.Nodes.Add(libraryNode);
libraryNode = null;
RecurseTree(subFolders, nLevel+1);
}
}

Any help appreciated!

Cheers


Dan

 
Hi Patrick,

Okay, basically you need to make sure all your IE Control stuff is added to
your form (you say you're using the tree so I suspect you've got that bit).

Your class for your webform *should* look something like this...

namespace yourNamespace
{
public class yourpage : System.Web.UI.Page
{
protected Microsoft.Web.UI.WebControls.TreeView yourtree;

private void Page_Load(object Sender, System.EventArgs e)
{
// page laod stuff here

// here we expand the tree
ExpandAll()
}

private void ExpandAll()
{
for(int i=0; i < yourTree.Nodes.Count; i++)
{
yourTree.Nodes.Expanded = true;
}
}
}

You need to make sure you reference Microsoft.Web.UI.WebControls at the top
of your page, like so...

using Microsoft.Web.UI.WebControls;

Hope this helps. Further information can be found by doing a search for "IE
Controls TreeView" on msdn.microsoft.com - and there's a walkthrough here...

http://msdn.microsoft.com/library/d...spp/html/aspnet-usingtreeviewiewebcontrol.asp

HTH


Dan



Patrick.O.Ige said:
Can u give me an example of the code behind and
How i should call it from Page_load.
Thx


Dan Nash said:
Hi Patrick

I'm also using the WebControl and it works fine. Just add the function to
your page class in CodeBehind and call it from your Page_Load event.
Obviously it's C#, so if you're using VB you'll have to rewrite accordingly,
but haven't got VB.net, sorry!

HTH


Patrick.O.Ige said:
Thx but i'm using the Treeview WebControl and i'm just loading my XML
the TreeNodeSrc= "Xmlfile"
Can i add the code u adviced? And where?



Patrick,

Try this..

private void ExpandAll()
{
for(int i=0; i < yourTree.Nodes.Count; i++)
{
yourTree.Nodes.Expanded = true;
}
}

This works for me, although there might be a simple command to do this
(haven't found one yet!). Obviously setting Expanded to false will give
you a
CollapseAll function as well :)

HTH


Dan
:

Hi Dan,
Do u have a way of the possibilty of Expanding All /Collapsing All
treeviews?
let me know and thx


Hi peeps..

Im using the TreeView control from IE COntrols to create a directory
structure, and trying to do it recursively.

The code works, but my question is simply how can I make the subdirs
appear
as leaves in the Tree, rather than as new branches?

Here's the code..

private void RecurseTree(DirectoryInfo theDir, int nLevel)
{
TreeNode libraryNode = null;
DirectoryInfo[] subFolders = theDir.GetDirectories();

// populate the tree
for (int i=0; i < subFolders.Length; i++)
{
libraryNode = new TreeNode();
libraryNode.Text = subFolders.Name;
treeDocuments.Nodes.Add(libraryNode);
libraryNode = null;
RecurseTree(subFolders, nLevel+1);
}
}

Any help appreciated!

Cheers


Dan

 
Thx mate!!



Dan Nash said:
Hi Patrick,

Okay, basically you need to make sure all your IE Control stuff is added to
your form (you say you're using the tree so I suspect you've got that bit).

Your class for your webform *should* look something like this...

namespace yourNamespace
{
public class yourpage : System.Web.UI.Page
{
protected Microsoft.Web.UI.WebControls.TreeView yourtree;

private void Page_Load(object Sender, System.EventArgs e)
{
// page laod stuff here

// here we expand the tree
ExpandAll()
}

private void ExpandAll()
{
for(int i=0; i < yourTree.Nodes.Count; i++)
{
yourTree.Nodes.Expanded = true;
}
}
}

You need to make sure you reference Microsoft.Web.UI.WebControls at the top
of your page, like so...

using Microsoft.Web.UI.WebControls;

Hope this helps. Further information can be found by doing a search for "IE
Controls TreeView" on msdn.microsoft.com - and there's a walkthrough here...http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnaspp/html
/aspnet-usingtreeviewiewebcontrol.asp

HTH


Dan



Patrick.O.Ige said:
Can u give me an example of the code behind and
How i should call it from Page_load.
Thx


Dan Nash said:
Hi Patrick

I'm also using the WebControl and it works fine. Just add the function to
your page class in CodeBehind and call it from your Page_Load event.
Obviously it's C#, so if you're using VB you'll have to rewrite accordingly,
but haven't got VB.net, sorry!

HTH


:

Thx but i'm using the Treeview WebControl and i'm just loading my XML
the TreeNodeSrc= "Xmlfile"
Can i add the code u adviced? And where?



Patrick,

Try this..

private void ExpandAll()
{
for(int i=0; i < yourTree.Nodes.Count; i++)
{
yourTree.Nodes.Expanded = true;
}
}

This works for me, although there might be a simple command to do this
(haven't found one yet!). Obviously setting Expanded to false will give
you a
CollapseAll function as well :)

HTH


Dan
:

Hi Dan,
Do u have a way of the possibilty of Expanding All
/Collapsing
All
treeviews?
let me know and thx


Hi peeps..

Im using the TreeView control from IE COntrols to create a directory
structure, and trying to do it recursively.

The code works, but my question is simply how can I make the subdirs
appear
as leaves in the Tree, rather than as new branches?

Here's the code..

private void RecurseTree(DirectoryInfo theDir, int nLevel)
{
TreeNode libraryNode = null;
DirectoryInfo[] subFolders = theDir.GetDirectories();

// populate the tree
for (int i=0; i < subFolders.Length; i++)
{
libraryNode = new TreeNode();
libraryNode.Text = subFolders.Name;
treeDocuments.Nodes.Add(libraryNode);
libraryNode = null;
RecurseTree(subFolders, nLevel+1);
}
}

Any help appreciated!

Cheers


Dan

 
No probs mate, hope it helped. Any probs just post again or email me.

Cheers

Dan

Patrick.O.Ige said:
Thx mate!!



Dan Nash said:
Hi Patrick,

Okay, basically you need to make sure all your IE Control stuff is added to
your form (you say you're using the tree so I suspect you've got that bit).

Your class for your webform *should* look something like this...

namespace yourNamespace
{
public class yourpage : System.Web.UI.Page
{
protected Microsoft.Web.UI.WebControls.TreeView yourtree;

private void Page_Load(object Sender, System.EventArgs e)
{
// page laod stuff here

// here we expand the tree
ExpandAll()
}

private void ExpandAll()
{
for(int i=0; i < yourTree.Nodes.Count; i++)
{
yourTree.Nodes.Expanded = true;
}
}
}

You need to make sure you reference Microsoft.Web.UI.WebControls at the top
of your page, like so...

using Microsoft.Web.UI.WebControls;

Hope this helps. Further information can be found by doing a search for "IE
Controls TreeView" on msdn.microsoft.com - and there's a walkthrough here...http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnaspp/html
/aspnet-usingtreeviewiewebcontrol.asp

HTH


Dan



Patrick.O.Ige said:
Can u give me an example of the code behind and
How i should call it from Page_load.
Thx


Hi Patrick

I'm also using the WebControl and it works fine. Just add the function to
your page class in CodeBehind and call it from your Page_Load event.
Obviously it's C#, so if you're using VB you'll have to rewrite
accordingly,
but haven't got VB.net, sorry!

HTH


:

Thx but i'm using the Treeview WebControl and i'm just loading my XML
the TreeNodeSrc= "Xmlfile"
Can i add the code u adviced? And where?



Patrick,

Try this..

private void ExpandAll()
{
for(int i=0; i < yourTree.Nodes.Count; i++)
{
yourTree.Nodes.Expanded = true;
}
}

This works for me, although there might be a simple command to do this
(haven't found one yet!). Obviously setting Expanded to false will
give
you a
CollapseAll function as well :)

HTH


Dan
:

Hi Dan,
Do u have a way of the possibilty of Expanding All /Collapsing
All
treeviews?
let me know and thx


Hi peeps..

Im using the TreeView control from IE COntrols to create a
directory
structure, and trying to do it recursively.

The code works, but my question is simply how can I make the
subdirs
appear
as leaves in the Tree, rather than as new branches?

Here's the code..

private void RecurseTree(DirectoryInfo theDir, int nLevel)
{
TreeNode libraryNode = null;
DirectoryInfo[] subFolders = theDir.GetDirectories();

// populate the tree
for (int i=0; i < subFolders.Length; i++)
{
libraryNode = new TreeNode();
libraryNode.Text = subFolders.Name;
treeDocuments.Nodes.Add(libraryNode);
libraryNode = null;
RecurseTree(subFolders, nLevel+1);
}
}

Any help appreciated!

Cheers


Dan

 
Hi Dan i'm getting error:-
'AddressOf' operand must be the name of a method; no parentheses are needed.
I use VB.Net and i changed the C# code from:-
private void ExpandAll()
{
for(int i=0; i < yourTree.Nodes.Count; i++)
{
yourTree.Nodes.Expanded = true;
}
}
TO

Public Sub ExpandAll()
Dim i As Integer
For i = 0 To tvFamilyTree.Nodes.Count - 1 Step i + 1
tvFamilyTree.Nodes(i).Expanded = True
Next
End Sub

And called ExapndAll in page load
And on my ASP.NET page called it like this:-
<asp:Button BorderColor=#009966 Runat=server
OnClick="ExpandAll()"></asp:Button>

Can u telling me what 'm doing wrong!!
Thx



Dan Nash said:
Don't worry about the subnodes question - I've sorted it with...

tree.Nodes.Nodes.Add()

Ta tho :)

Dan Nash said:
Hi peeps..

Im using the TreeView control from IE COntrols to create a directory
structure, and trying to do it recursively.

The code works, but my question is simply how can I make the subdirs appear
as leaves in the Tree, rather than as new branches?

Here's the code..

private void RecurseTree(DirectoryInfo theDir, int nLevel)
{
TreeNode libraryNode = null;
DirectoryInfo[] subFolders = theDir.GetDirectories();

// populate the tree
for (int i=0; i < subFolders.Length; i++)
{
libraryNode = new TreeNode();
libraryNode.Text = subFolders.Name;
treeDocuments.Nodes.Add(libraryNode);
libraryNode = null;
RecurseTree(subFolders, nLevel+1);
}
}

Any help appreciated!

Cheers


Dan
 
Back
Top