473,398 Members | 2,212 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,398 software developers and data experts.

TreeViews

Hi to all,

When i use the treeview and i add nodes to it, i have the problem of the
depth. I try to explain myself.

depending of the number of nodes i add or the place where i add it, i have
to use the treeview following this sentences:

treeview1.Nodes.Add
or
treeview1.Nodes[x].Nodes.Add
or
treeview1.nodes[x].Nodes[y].Nodes.Add().
and so on...

how could programatically add nodes only in one method with one sentence? my
problem is that i dont compose this treeview from a query from database. i
want to generate each node when a event is fired in a class that i have. I
want to subscribe to this event and when the event is fired use only a
sentence.

--
Thanks
Regards.
Josema
Jun 27 '06 #1
2 1664
Bry
Josema wrote:
Hi to all,

When i use the treeview and i add nodes to it, i have the problem of the
depth. I try to explain myself.

depending of the number of nodes i add or the place where i add it, i have
to use the treeview following this sentences:

treeview1.Nodes.Add
or
treeview1.Nodes[x].Nodes.Add
or
treeview1.nodes[x].Nodes[y].Nodes.Add().
and so on...

how could programatically add nodes only in one method with one sentence? my
problem is that i dont compose this treeview from a query from database. i
want to generate each node when a event is fired in a class that i have. I
want to subscribe to this event and when the event is fired use only a
sentence.

--
Thanks
Regards.
Josema


Could you use recursion?

I have a C++ CLR class (which I've roughly translated to C# below
without testing) that uses recursion to populate a treeview with the OU
structure of an AD domain

public void PopulateADTreeViewRecurse(TreeNode Node, DirectorySearcher
searcher)
{
SearchResultCollection results = searcer.FindAll();
foreach (SearchResult result in results)
{
DirectoryEntry de = result.GetDirectoryEntry();
TreeNode newNode = new
TreeNode(de.Properties["Name"][0].ToString(), 1, 2);
node.Nodes.Add(newNode);
newNode.Tag = de;

DirectorySearcher newSearcher = new DirectorySearcher(de,
"(objectClass=organizationalUnit)");
newSearcher.SearchScope = SearchScope.OneLevel;

PopluateADTreeViewRecurse(newNode, newSearcher);
}
}

I would call this class with the following code

DirectoryEntry rootDSE = new DirectoryEntry("LDAP://rootDSE");
string path = "LDAP://" +
rootDSE.Properties["defaultNamingContext"][0].ToString();
string nodeText =
rootDSE.Properties["defaultNamingContext"][0].ToString() + " [" +
rootDSE.Properties["dnsHostName"][0].ToString() + "]";
// The following treeView has already been created by the form designer
treeView.Nodes.Clear();
TreeNode node = new TreeNode(nodeText, 0, 0);

DirectoryEntry directoryRoot = new DirectoryEntry(path);
DirectorySearcher searcher = new DirectorySearcher(directoryRoot,
"(objectClass=organizationUnit)");
searcher.SearchScope = SearchScope.OneLevel;
PopulateADTreeViewRecurse(node, searcher);
treeView.Nodes.Add(node);

Hope that is of some help.

Jun 27 '06 #2
There is a way to return what "level" or "depth" of the treeview you
are in.

int treelevel = 0;
TreeNode tnTemp = treeView1.SelectedNode;
while(tnTemp.Parent != null)
{
treelevel++;
tnTemp = (TreeNode)tnTemp.Parent;
}
Msg(treelevel.ToString()); - will be the current level 0 being root.

Josema wrote:
Hi to all,

When i use the treeview and i add nodes to it, i have the problem of the
depth. I try to explain myself.

depending of the number of nodes i add or the place where i add it, i have
to use the treeview following this sentences:

treeview1.Nodes.Add
or
treeview1.Nodes[x].Nodes.Add
or
treeview1.nodes[x].Nodes[y].Nodes.Add().
and so on...

how could programatically add nodes only in one method with one sentence? my
problem is that i dont compose this treeview from a query from database. i
want to generate each node when a event is fired in a class that i have. I
want to subscribe to this event and when the event is fired use only a
sentence.

--
Thanks
Regards.
Josema


Jun 27 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: j_mckitrick | last post by:
I'm using a basic MVC TreeView in GTK, but this isn't a GTK question. I have a set of objects and show their properties in a TreeView. I TreeView has a ListStore which can be modified, and the...
0
by: Gurudev | last post by:
Is it possible to create an explorer style drag and drop for treeviews in C# i.e. the selected node text appears and moves along with the cursor while dragging thanks in advance --...
3
by: sho_nuff | last post by:
Hello all, I want to create a List of TreeViews in either a ListView or ListBox component. The result would be a list object that for the first row has a tree like: com -foo
4
by: Michael C# | last post by:
I have a quick question, and was just wondering if anyone knew a good resource, article(s) or sample source code. I want to be able to connect the nodes of two treeviews graphically via lines. I...
1
by: emferrari | last post by:
Hi everybody I have two treeviews, one of them is only to receive items dragged from the treeview1. I want to know how to drag a full node information to the treeview2. I know how to do that...
3
by: Woody Splawn | last post by:
I have been experimenting with Auto Slides and TreeViews and find them most usefull in Winforms. I know how to create a Treview and have it, for example, slide out from the left of my Winform but...
1
by: jotaefe | last post by:
Hi there, Anybody knows if it is possible to highlight nodes on a treeview (over) on a drag and drop operation from a different treeview? The two treeviews are in the same Windows form. Your...
3
Raventara
by: Raventara | last post by:
Hi-a all, I have two treeviews on a form (VB.NET) and one of them contains words, and the other commands. Each word has a command assigned to it. I chose to show this in a treeview as certain words...
0
by: track | last post by:
I have two treeviews say TreeviewA and TreeviewB on windows form in .Net. I want to transfer node from TreeviewA to TreeviewB based on selected node under TreeviewB. But problem is when I select...
6
by: SalimZaabi | last post by:
How do I contruct a series of treeViews to display a folder with subfolders and files ?? I tried but all my tries were stuck on the second subtreeView!! how to keep the treeView going whenever...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.