473,394 Members | 1,702 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,394 software developers and data experts.

Specifying the parent when adding treeview nodes?

I'm using the EnumChildWindows API with an EnumChildWndProc callback
to populate the treeview. The output will be something similar to spy+
+

How can I specify the parent when adding a new node ??

When adding a new node is there any way to get an handle or something
else to be able add the childs to the correct parent ?

Thanks!
Nov 27 '07 #1
6 2473
On 2007-11-27 13:30:35 -0800, SQACSharp <ls*********@hotmail.comsaid:
I'm using the EnumChildWindows API with an EnumChildWndProc callback
to populate the treeview. The output will be something similar to spy+
+

How can I specify the parent when adding a new node ??

When adding a new node is there any way to get an handle or something
else to be able add the childs to the correct parent ?
If I understand the question correctly, the fact that you are
enumerating windows is irrelevant to your question.

And again, assuming I understand the question correctly, the answer is
that you simply add the node to the Nodes collection of the node you
want to be the parent. For a root-level node, this will be the Nodes
collection of the TreeView itself, and for any other node, this will be
the Nodes collection of a TreeNode.

If that doesn't answer your question, you should rephrase your
question, explaining the relevance of the window enumeration if there
is any, and more specifically describing what it is you actually want
to do.

Pete

Nov 27 '07 #2
You can only get the Parent property on the TreeNode class. If you want
to add a TreeNode as a child of another TreeNode, you have to have a
reference to the parent TreeNode, and call the Add method on the Nodes
collection exposed by the parent.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"SQACSharp" <ls*********@hotmail.comwrote in message
news:9c**********************************@d4g2000p rg.googlegroups.com...
I'm using the EnumChildWindows API with an EnumChildWndProc callback
to populate the treeview. The output will be something similar to spy+
+

How can I specify the parent when adding a new node ??

When adding a new node is there any way to get an handle or something
else to be able add the childs to the correct parent ?

Thanks!

Nov 27 '07 #3
On 2007-11-27 15:01:07 -0800, SQACSharp <ls*********@hotmail.comsaid:
Sorry it's hard to explain for me, so maybe you will understand the
problem of enumerating child windows and adding the node to the
correct parent with an example :
Basically, you need to keep track of the node corresponding to the
parent. There are lots of ways you might do this, but in the code you
posted, it might look something like this (original code quoted, new
code unquoted):
[...]
foreach (string MyWindow in ListOfWindows)
{
TreeNode nodeParent = new TreeNode(MyWindow);
// Add a node for each windows associated to the processId
MyNode.Nodes.Add(nodeParent));
>
foreach (string child in
(ArrayList)ListOfChildWindows[WindowCounter])
{
//Add all the childs associated to the window

//*** PROBLEM BEGIN ***
//The following node must be added to the correct
parent..it's added to the same level as other windows for now
nodeParent.Nodes.Add("->"+child.ToString());
>
//*** PROBLEM END ***
}
WindowCounter++;
}
}
I am curious whether you care that you've only obtained a list one
level deep in the window hierarchy. Any window can have a child
window, and so you really ought to have some kind of recursive
operation that actually does enumerate every window of the process,
rather than just the non-child windows and their children.

But assuming that the one-level-deep is sufficient for your needs, the
above change should work for you.

Pete

Nov 27 '07 #4
Ok... I will try to explain the problem again :

EnumChildWindows return **ALL** child windows of a given handle. A
child window can also be a parent of another child and so on... So
when adding childs, the parent can be the main window or any other
child returned by enumChildWindow.

The only thing i know is the parent handle returned by Win32
GetParent. I'm trying to find a way to select the correct node with
the correct handle to add the child node.

Example of a window :
MainWindows1, Handle=12345
|----Label1, Handle=54321
|----GroupBox1 , Handle=11111
|---- CheckBox1, Handle=666 (the parent of checkbox1 is the
child groupbox1 and not the main window)

So when calling EnumChildWindows it return label1, groupbox1 and
checkbox1..... When adding the node for checkbox1 how to tell that the
node must be created under the node GroupBox1 (with the handle 11111)

The solution can be to use the key to store the handle of the
window... but i'm still trying to find the way to found the node with
a specific key and being able to add a child node under it.

Thanks again...
Nov 28 '07 #5
On 2007-11-27 17:23:47 -0800, SQACSharp <ls*********@hotmail.comsaid:
Ok... I will try to explain the problem again :

EnumChildWindows return **ALL** child windows of a given handle. A
child window can also be a parent of another child and so on... So
when adding childs, the parent can be the main window or any other
child returned by enumChildWindow.
Ah. For some reason I was thinking it behaved the same as GetWindow().
It's been awhile.

It didn't help that your original code didn't even put the child
windows under the thread node in the TreevView. It was a bit confusing
to try to understand what exactly you were trying to do.

Anyway, as far as the specific question goes...

One possible solution would be in fact to use GetWindow() to enumerate
the windows in the process. That way your enumeration could be done in
a recursive method that also tracks the current parent node so that it
could be handled appropriately.

Alternatively, you could store the TreeNode instances you create in a
Dictionary<IntPtr, TreeNode>, where the window handle corresponding to
the node is used for the key. Then when adding a TreeNode, you can use
GetParent() to get the window handle for the parent of the current
node's window handle, use that to look up the appropriate TreeNode and
add the current node to that node's Nodes collection.

There are actually lots of other ways to do this, assuming I finally
understand the question correctly. But I think the two methods above
are good representations of the two basic ideas you might use. That
is, either:

1) enumerate the child windows in a way such that you always know
the relationship of the current node in the enumeration to its parent.
This is likely to always involve some kind of recursion, whether
explicitly as a recursive method or using a stack data structure to
maintain the state of the enumeration.

2) retrieve the parent information from the current node, given the
window handle of the parent. A dictionary is an efficient way to do
this, but you could do a brute-force search of the TreeViews nodes if
you really wanted to.

If the above doesn't help, you'll have to try to elaborate again I think.

Pete

Nov 28 '07 #6
Thanks peter and Nicholas for trying to help.. I really appreciate
your help and thank you for your time!! :)

I found the solution after loosing all the day on this :

When adding the node I use the .Add function with two parameters (the
keys and the text). The window handle is stored in the key
parameter. Then, when adding my child node I simply use the .Find
function to search the parent node with the handle. The TreeNode
returned by the .Find function can be use to add nodes!
Nov 28 '07 #7

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

Similar topics

1
by: clintonG | last post by:
How do I get a TreeNode.Parent property when using the 2.0 TreeView control? When the data source is an XML file there may be redundant names in the tree. For example, when a child node with the...
3
by: sho_nuff | last post by:
Question here: I have been trying to find a way to add existing nested nodes to a tree that already has nodes in it: So, my tree looks like this: -com -foo -goo
4
by: Chuck Bowling | last post by:
I have a serialized TreeNodeCollection that I want to initialize a TreeView with. Is there a simple assignment I can use for this or do I have to iterate thru the collection and add individual...
3
by: MrNobody | last post by:
Ok, so I'm absoultely positive this was working last night, but today I'm getting this error in my program when I try to add a child node to a parent node of a tree... The error says: ...
0
by: usamaalam | last post by:
Hello everybody, I have a treeview control in my application and a hierarchy of sub-nodes. Application works on rights. If user doesnt have rights to see a particular screen, the treeview node...
3
by: Brian Henry | last post by:
If i already have a tree view created, and want to add another new node to it, how would i do so? Is there a way to throught tags or anything? like i have this RootNode | +-- Child 1 +--...
4
by: pmcguire | last post by:
I have a treeview with a lot of nodes. I want to load only the nodes that are initially visible when the form loads, and then continue to populate it in background and/or when the nodes are required...
7
by: amruta | last post by:
the code below dows not let me get the parent child view... all the nodes are show in one line only... also i need them to be collasped ... Thanks ..
4
by: jmDesktop | last post by:
I have searched everywhere and tried several things. I have a treeview with and want to be able to only select a parent node. For example: root //don't want to drag this -parent1 //yes, drag...
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: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
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...

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.