View Full Version : Selecting item in dotnet treeview
I have a dotNet tree view control and I want to have one of the items selected when it opens. How is this done? I have been poking around for ages. I can get what is selected just not set what is selected. Any ideas?
|
|
ypuech
09-12-2007, 09:42 PM
To set a dotNet TreeView selected node, just assign to the SelectedNode property the node (TreeNode value) you want to be selected.
RustyKnight
09-12-2007, 11:42 PM
This is probably extraoridinarly obvious, but make sure that the tree is populated first
Ah, so I gather there is no way to do it directly with the index. I will have to get the node that I want and then pass that into the selectedNode property.
I will give this a try. Thanks. Oh, and the tree is populated.
Here it is,
tv.selectedNode=tv.nodes.item[0]
This will select the first node in the tree.
Thanks guys.
Looking back at my test code I did try this, I on way to much allergy meds to remember anything this time of year. how ever I didn't think that it was working because the node that is selected will not show if the treeview is not in focus. This is unlike list boxes in Max where you can still see what is in focus. To get around this problem I'm having to set the back ground colour instead which will show up. This is working very well. Just a heads up for others.
ypuech
09-14-2007, 02:17 PM
You can also force focus calling tv.Focus().
Didn't work in my case as I don't want focus on the tv control. I just want to know visualy what is selected in the list.
magicm
09-14-2007, 07:31 PM
This forces the selected item to be visible even when the treeview is not in focus:
tv.HideSelection = false
Martijn
ypuech
09-14-2007, 07:50 PM
Thanks for the info Martjin.
Never seen this property before. It works also with ListView controls.
This is great, thanks. I hadn't seen that either.
CGTalk Moderation
09-17-2007, 11:07 AM
This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum.
vBulletin v3.0.5, Copyright ©2000-2012, Jelsoft Enterprises Ltd.