This is a migrated thread and some comments may be shown as answers.

How to force a refresh/update?

6 Answers 3853 Views
Treeview
This is a migrated thread and some comments may be shown as answers.
Kristoffer
Top achievements
Rank 1
Kristoffer asked on 13 Feb 2013, 11:47 AM
When a property is changed through my property grid, I want to make sure the tree is up to date.

private void radPropertyGridNode_PropertyValueChanged(object sender, PropertyGridItemValueChangedEventArgs e)
{
     radTreeView.Refresh();
}

Refresh() does not work.
Invalidate() does not work.
Update() does not work.

Hovering the control using the mouse does work.

How can I programmatically update the tree so that it fires the NodeFormatting event (where my nodes are updated)?

6 Answers, 1 is accepted

Sort by
1
Julian Benkov
Telerik team
answered on 18 Feb 2013, 06:54 AM
Hi Kristoffer,

You can use the
Update method of the TreeViewElement to update the current view of the control:
treeView.TreeViewElement.Update(RadTreeViewElement.UpdateActions.Resume);
or
treeView.TreeViewElement.Update(RadTreeViewElement.UpdateActions.Reset);

I hope this helps.

Regards,
Julian Benkov
the Telerik team
Q3'12 SP1 of RadControls for WinForms is out now. See what's new.
0
Kristoffer
Top achievements
Rank 1
answered on 18 Feb 2013, 10:27 AM
Thanks. That did the trick!
0
Andrew Chandler
Top achievements
Rank 2
answered on 13 Jan 2021, 06:15 PM

I have been struggling with this in the TreeView control.  updating a node by the underlying datasource and getting the text on the node to change or to get the child nodes of a parent node to resort based on the newly updated node text.

What is the difference in the two above items?  And what is the standard method of updating the nodes data source and getting that node to change or the subset of nodes to change?

0
Dess | Tech Support Engineer, Principal
Telerik team
answered on 14 Jan 2021, 09:44 AM
Hello, Andrew,   

The TreeViewElement.Update method allows you to update the tree view passing an appropriate UpdateAction according to the performed operation, e.g. adding a new record, updating an existing one.

RadTreeView is a control that allows you to visualize hierarchical structures of data in the form of a tree. However, when using bound mode, when a change in the underlying data source occurs, the tree needs to repopulate itself in order to get the latest changes. The following help articles demonstrates a sample approach how to update the tree view in order to show the latest changes in the DatSource: https://docs.telerik.com/devtools/winforms/controls/treeview/how-to/keep-radtreeview-states-on-reset 

I hope this information helps. If you need any further assistance please don't hesitate to contact me. 

Regards,
Dess | Tech Support Engineer, Sr.
Progress Telerik

Virtual Classroom, the free self-paced technical training that gets you up to speed with Telerik and Kendo UI products quickly just got a fresh new look + new and improved content including a brand new Blazor course! Check it out at https://learn.telerik.com/.

0
Andrew Chandler
Top achievements
Rank 2
answered on 14 Jan 2021, 03:50 PM

Thank you for the response.  My questions were posted regarding the TreeView items above.  Namely,

You can use the Update method of the TreeViewElement to update the current view of the control:

treeView.TreeViewElement.Update(RadTreeViewElement.UpdateActions.Resume);

or
treeView.TreeViewElement.Update(RadTreeViewElement.UpdateActions.Reset);

 

I am wanting to know the difference when you would use UpdateActions.Reset vs UpdateActions.Resume.

As for the state saving abilities, I found the state saving code researching previously and turned them into extension methods.  Those would be nice additions to the TreeView and TreeNode controls.  Thank you for the link. 

My current issue is with self referencing databinding in a TreeView control.  When I change the Parent value in the underlying datasource, my dataSource being a BindingList<MyObject>, it changes the Text of the node on Reset or Resume, but does not Move the node to the new parent.  I have to detach the TreeView Datasource object, set the DataSource to Null and set it back, then apply the state back to the tree.

Is there an easier way to accomplish this or a "right" way to accomplish this?

I am also very glad you responded to this question.  I have read many of your posts on these forums and you continue to give the little details about the workings of the controls that other responders leave out.  Those are very much appreciated.

 

 

 

0
Dess | Tech Support Engineer, Principal
Telerik team
answered on 15 Jan 2021, 12:43 PM
Hello, Andrew, 

UpdateActions.Reset internally suspends the layout, removes and detaches the first visual node element, resumes the layout and clears the cache.
UpdateActions.Resume updates the layout and forces the SynchronizeNodeElements method.

When you are using self-referencing hierarchy in RadTreeView, please note that the hierarchy is built according to the specified Id/ParentId properties. When you update an item from the BindingList, e.g. changing the text, it is OK to use the Update method. However, when you change the parent for a certain record, it is necessary to force rebuilding the hierarchy. 

Rebinding is a suitable approach to force the hierarchy structure to rebuild.

Should you have further questions please let me know.

Regards,
Dess | Tech Support Engineer, Sr.
Progress Telerik

Virtual Classroom, the free self-paced technical training that gets you up to speed with Telerik and Kendo UI products quickly just got a fresh new look + new and improved content including a brand new Blazor course! Check it out at https://learn.telerik.com/.

Tags
Treeview
Asked by
Kristoffer
Top achievements
Rank 1
Answers by
Julian Benkov
Telerik team
Kristoffer
Top achievements
Rank 1
Andrew Chandler
Top achievements
Rank 2
Dess | Tech Support Engineer, Principal
Telerik team
Share this question
or