473,765 Members | 2,010 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Specifying the parent when adding treeview nodes?

I'm using the EnumChildWindow s API with an EnumChildWndPro c 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 2516
On 2007-11-27 13:30:35 -0800, SQACSharp <ls*********@ho tmail.comsaid:
I'm using the EnumChildWindow s API with an EnumChildWndPro c 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.co m

"SQACSharp" <ls*********@ho tmail.comwrote in message
news:9c******** *************** ***********@d4g 2000prg.googleg roups.com...
I'm using the EnumChildWindow s API with an EnumChildWndPro c 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*********@ho tmail.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(MyWind ow);
// Add a node for each windows associated to the processId
MyNode.Nodes.Ad d(nodeParent));
>
foreach (string child in
(ArrayList)List OfChildWindows[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.Node s.Add("->"+child.ToStri ng());
>
//*** 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 :

EnumChildWindow s 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 EnumChildWindow s 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*********@ho tmail.comsaid:
Ok... I will try to explain the problem again :

EnumChildWindow s 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<IntP tr, 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
1960
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 value of 'name' is selected I don't have a clue how to get the name of its parent which may be 'person' or 'school.' <%= Clinton Gallagher
3
2900
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
13154
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 Nodes?
3
3166
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: Message: The action being performed on this control is being called from the wrong thread. You must marshal to the correct thread using Control.Invoke or Control.BeginInvoke to perform this action. Stack Trace: at...
0
1663
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 hides and user doesn't know there is some option of this screen in the application. Suppose I have a parent treeview node "Administrator", with a sub-node "Setup". "Setup" contains three more nodes, "Backup","Restore", "Reset". If user doesn't have...
3
2488
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 +-- Child 2 and i want to add a child node to child 1 how would i refrence it and add a
4
2313
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 by the user either scrolling or performing some other action that would move the treeview window to a particular "unloaded" node in the treeview Any advice on how to go about this? It seems I need a way of sensing a scroll event in the treeview...
7
3770
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
3585
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 this an only this because it is a parent --childOfParent1 //cannot drag this, only the parent --childOfParent1 //can only drag parent -parent2 //yes, parent, can select and drag --childOfParent2 //no, cannot drag
0
9568
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9404
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10007
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
7379
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5277
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5423
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3926
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3532
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2806
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.