Treeview control determining if node expanded or selected

L

l.holmes

Hi

I have a asp.net 2.0 treeview control which I populate nodes using the new
client call back (populatenodeondemand = true).

This works fine and my _TreeNodePopulate event handler handles the event
fired when a node is expanded and populates the child nodes.

However, I now need to use the treeview in a slightly different way. When
expanding a node I want my existing code to populate child nodes on demand.
But when a node is selected I want to call some other server side code.

It seems that my _TreeNodePopulate event handler is called even when I
select a node by clicking on the node text. Also the e.Node.Value does not
refer to the node I select but the parent node in the treeview!

I cannot seem to find a way to determine if the node has been expanded or
selected in order to call the correct code.

I have tried setting the SelectAction to various values and I also have
tried checking the e.node.Selected property but it always returns false even
when I have selected a node.

Please can someone explain how I can determine if the node refered to in the
event has been expanded ot selected.


Thanks

Lewis Holmes
eNate
 
C

CaffieneRush

Hi,

In the MSDN example for TreeNode.PopulateOnDemand() - the strategy is:
Within the OnTreeNodePopulate handler
1. Create and set non-leaf nodes' PopulateOnDemand to true.
2. Set non-leaf nodes' SelectAction to Expand.
3. Create and set the leaf nodes' PopulateOnDemand to false
4. Set the leaf nodes' SelectAction to Select.
http://msdn2.microsoft.com/en-US/li...ontrols.treenode.populateondemand(VS.80).aspx

This is because for most situations it is *only* the leaf nodes that
should raise the select event and this would neatly sidestep your
problem.
You can then handle the SelectNodeChanged event and process the leaf
nodes that were selected.

Hope that was clear.
 
S

Steven Cheng[MSFT]

Hi Lewis,

As for the TreeView control's TreeNodes, for non-leaf child nodes, if you
only want to expand them and populate new nodes, but do not want to do any
processing when selecting them, you can follow the strategy mentioned in
the msdn reference Caffiene has mentioned. If those non-leaf child nodes
need both selecting and populating event, I think you need to set the their
"SelectAction" to "Select". Thus, when we click on the node (the text),
only "SelectedNodeChanged" event will be fired and for "populate" event, it
will fire only when we click the "+" flag, and this will fire once for each
node.

Regards,

Steven Cheng
Microsoft Online Community Support


==================================================

When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.

==================================================


This posting is provided "AS IS" with no warranties, and confers no rights.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,007
Latest member
obedient dusk

Latest Threads

Top