Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
18495
How to refresh tree with new data from database and keep nodes expanded
posted

I've had some customers create cases asking how to keep the nodes of the UltraTree expanded after it's been refreshed with new data.  The sample I've attached shows exactly how to do this.

DataboundWinTree.zip
  • 35
    Offline posted

    var expandedNodes = new BindingList<String>();
    foreach (var node in ultraTree1.Nodes)
    {
    	if (node.Expanded)
    	{
    		expandedNodes.Add(node.Key);
    	}
    }
    
    ultraTree1.BeginUpdate();
    this.parentTableAdapter.Fill(this.dataSet1.Parent);
    this.childTableAdapter1.Fill(this.dataSet1.Child);
    ultraTree1.EndUpdate();
    
    foreach (var key in expandedNodes)
    {
    		var node = ultraTree1.Nodes[key];
    		node.Expanded = true;
    }

    Code had a defunct dependency, but this is the gist of it.