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
740
Select a node from tree with less loading time
posted

Hi everyone,

I have a tree which display components and the tree's DataSource has been set to a DataTable. I need to select particular component(Node) programatically using some conditions and select that node. Also when it is selected, I want the node's parent and children nodes should be expanded, not all nodes in the tree. I have used the following coding but it takes alooooot of time to load and to show the node.

In InitializeComponent()

this.utComponentTree.DataMember = "component$fk_componen_comp_topl_componen";

this.utComponentTree.DataSource = this.componentBindingSource;

 

When the Search button is clicked

/* dt has the values that should be compared with the treeNode value and utComponentTree is the UltraTree*/ 

List<UltraTreeNode> descendants = this.GetAllDescendants(utComponentTree.Nodes[0]); for (int i = 0; i < descendants.Count; i++)

{

if (((System.Data.DataRowView)(descendants[i].ListObject)).Row["component_id"].ToString() == dt.Rows[0]["component_id"].ToString() )

{

descendants[i].Selected =
true;

}

}

utComponentTree.ExpandAll(ExpandAllType.OnlyNodesWithChildren);

 

private List<UltraTreeNode> GetAllDescendants(UltraTreeNode node)

{

List<UltraTreeNode> retVal = new List<UltraTreeNode>();

this.GetAllDescendants(node.Nodes, retVal);

return retVal;

}

private void GetAllDescendants(TreeNodesCollection nodes, List<UltraTreeNode> descendants)

{

foreach (UltraTreeNode node in nodes)

{

descendants.Add(node);

if (node.HasVisibleNodes)this.GetAllDescendants(node.Nodes, descendants);

}

}

Is there an easy for to do this with less loading time? 

Please give me some code samples if possible. If anyone need clarifications pls let me know.

Thanks in Advance!

  • 69832
    Offline posted

    Accessing the child rows from the data source can be an expensive operation, so that might be the cause of the latency you are observing, since you are calling the control's ExpandAll method, which is causing the data source to retrieve all of its rows. You might want to consider only expanding the first root node, since it looks like that is the only one you are searching under.