|
-
Jul 9th, 2009, 09:05 AM
#1
Thread Starter
Frenzied Member
Dynamic TreeView issue - need help
I am trying to dynamically build a TreeView. I want to be able to expand a top level node & have any child nodes be added on the fly. The problem I'm running into is that I can't get the "+" symbol to appear if there are no subnodes to begin with. I could probably add a "dummy" subnode, then when the parent node is expanded I could delete the dummy node & add my real nodes, but that sounds cheesy. Can someone please explain the proper way to do this or point me to some code? Thanks...
-
Jul 9th, 2009, 09:31 AM
#2
Re: Dynamic TreeView issue - need help
Hmm... I think the simple answer is there isn't any way other than your "cheesy" way (which I don't think is cheesy by the way - it is used quite commonly).
The "+" is there to signify the presence of child nodes. If there are no child nodes there is no "+", simple as that.
The only other thing you may be able to do is make the treeview "owner-draw" (make the treeview's DrawMode = OwnerDrawAll) and you would be responsible for painting the content of the treeview yourself, which is a lot more hassle than doing it by creating dummy nodes.
-
Jul 9th, 2009, 09:50 AM
#3
Re: Dynamic TreeView issue - need help
This is something I've been intending to investigate for a while because I'd like to be able to do the same thing. I'm guessing that it's possible to inherit the TreeNode and/or TreeView classes and make this happen, although it might take some messing with unmanaged code. I'll schedule it for investigation this weekend and let you know how I get on.
-
Jul 9th, 2009, 11:34 AM
#4
Thread Starter
Frenzied Member
Re: Dynamic TreeView issue - need help
Please do let us know what you find out. My "cheesy" way does work, but I'm sure anything you come up with will be far more elegant.
-
Jul 9th, 2009, 01:09 PM
#5
Re: Dynamic TreeView issue - need help
I have to say I have always used the way you described. I just add a node that says "Loading..." or something like that so that if somehow the user does see it for a second before the proper nodes are added then thats all they see until the dynamic nodes are added. I dont really see anything wrong with this method but I would be interested to see if it could be done more 'properly'
-
Jul 9th, 2009, 01:14 PM
#6
Re: Dynamic TreeView issue - need help
You don't even need to see a temporary node at all if you populate your branch during the node BeforeExpand event.
-
Jul 9th, 2009, 01:24 PM
#7
Re: Dynamic TreeView issue - need help
Ah I see, never tried that but I will bear it in mind if I ever need to do that again 
PS it took me about 30 seconds to make this work the way you want to in WPF. Its the future, I'm telling you!
-
Jul 9th, 2009, 01:32 PM
#8
Re: Dynamic TreeView issue - need help
 Originally Posted by chris128
PS it took me about 30 seconds to make this work the way you want to in WPF. Its the future, I'm telling you!
I think it's a bit too early to say that right now. WPF could take off like a rocket or it could quitely die off in a few years just like many other technology innovations.
Let us have faith that right makes might, and in that faith, let us, to the end, dare to do our duty as we understand it.
- Abraham Lincoln -
-
Jul 9th, 2009, 01:38 PM
#9
Re: Dynamic TreeView issue - need help
You dont think the fact that the new version of the primary application that Windows developers use (Visual Studio) is made in WPF shows that it may be slightly more serious than "just another technology" ? I'm certainly not saying it is perfect and it needs to mature quite a lot still but I was just commenting on how easy it makes things like this...
Anyway I guess this is not really a discussion to be had in this thread
-
Jul 9th, 2009, 01:43 PM
#10
Re: Dynamic TreeView issue - need help
How would you want the TreeView to react to the following situation:
You have a TreeNode that has no children and you select it, the [+] box goes away. Then you navigate away from that node (by selecting a different one). Should the Node redraw that [+] OR should it stay cleared? Because potentially nodes could get dynamically added to that node after you select a different one.
-
Jul 9th, 2009, 01:46 PM
#11
Thread Starter
Frenzied Member
Re: Dynamic TreeView issue - need help
I think it should stay cleared. That's how I made mine behave.
-
Jul 9th, 2009, 01:48 PM
#12
Re: Dynamic TreeView issue - need help
Oh I thought the idea was that if the node did not have any children then it wouldnt get the plus symbol. I think it would look pretty naff having a plus symbol that when the user clicks it just disappears :S
-
Jul 9th, 2009, 01:52 PM
#13
Thread Starter
Frenzied Member
Re: Dynamic TreeView issue - need help
In my case, there's no way to know ahead of time if a node will have children or not, so I just always put the "+" there. If the user expands it & there are no child nodes, then it clears.
-
Jul 9th, 2009, 01:54 PM
#14
Re: Dynamic TreeView issue - need help
Oh right, would have taken even less time in WPF if I had known that (sorry stanav )
-
Jul 14th, 2009, 01:02 PM
#15
Thread Starter
Frenzied Member
Re: Dynamic TreeView issue - need help
JMC ... just wondering if you had a chance to investigate this...
-
Jul 14th, 2009, 09:16 PM
#16
Re: Dynamic TreeView issue - need help
 Originally Posted by nbrege
JMC ... just wondering if you had a chance to investigate this...
I had a look through the TreeView code in Reflector and didn't see anything that appeared useful. I'll take a closer look at the Win32 control some time soon.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|