Home - Forums-.NET - FlyTreeView (ASP.NET) - dynamically populate children nodes when parent is checked

FlyTreeView (ASP.NET)

Technical support and KB related to the FlyTreeView control

This forum related to following products: FlyTreeView for ASP.NET

dynamically populate children nodes when parent is checked
Link Posted: 10-Apr-2009 08:43
I'm trying to make this sample:
http://www.9rays.net/asp.net_2/treeview/Demo_Checkboxes_Adv.aspx

handle dynamically populated children nodes.
I modified the nodeEventHandler to add the *** line
if (eventType == \"checked\") {
  ***node.expand();
  setChildrenCheckBox(node, true);

but the problem is the node expands but when setchildrencheckbox is called, the node hasn't expanded yet.
Is there a "wait for node to expand" function I can call after node.expand()?
Link Posted: 10-Apr-2009 08:46
No you cannot wait in this case, because node is expanded asynchronously.
But, you can handle the "populated" event and do what you want there.
Link Posted: 10-Apr-2009 09:54
but how do I know whether in the populated event whether someone clicked on the "expand" button or whether they clicked on the checkbox of the parent?
The sample probably needs to be updated for this too..
Link Posted: 10-Apr-2009 10:06
Ok, you handle checked, in this handler you remember what node was expanded using this handler (e.g. you can put it in global nodesExpandedByChecked array).

So when populated event occurs, you just check if this node is in array of nodes that were expanded using checkbox.
Link Posted: 10-Apr-2009 11:09
Thanks Evgeny.  Here are the changes I had to make in case you want to add it to your sample

Add global variable:
var treeview_checknode = null;

Modifications to nodeEventHandler():
...
if (eventType == "checked") {
      treeview_checknode = node.getValue();
      node.expand();   // try to expand node
...
} else if (eventType == "populated") {
      if (treeview_checknode == node.getValue()) {
         setChildrenCheckBox(node, true);
         treeview_checknode = null;
      }
}
Link Posted: 10-Apr-2009 22:57
Good.
But I would rather use array instead of single treeview_checknode.
Because user can check multiple nodes while first one checked is still loading.