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

Maintain selection after setting datasource

1 Answer 83 Views
Treeview
This is a migrated thread and some comments may be shown as answers.
Mark
Top achievements
Rank 1
Mark asked on 02 Nov 2011, 10:02 PM
Hi,

I am using the RadTreeView (RTV) control to display a list of IP addresses.  The datasource of the RTV is set on form load, with the data source set to a BindingList of a custom class.  This all works fine.

The problem happens when I update the BindingList using a standard Timer control, with the selected item in of the RTV de-selecting, thus requiring it to be selected again.  I have attempted to store and set the selection, however this still causes momentary blinking of the selecting.  I've also tried to SuspendLayout, the ResumeLayout without success.

The above issue also occurs with the hover style, which for 'ControlDefault' theme is a lighter orange colour, with the background colour switching between this and white on refresh of the BindingList.

Please help!

1 Answer, 1 is accepted

Sort by
0
Jack
Telerik team
answered on 07 Nov 2011, 09:48 AM
Hello Mark,

This behavior is desired, because when the BindingContext changes, RadTreeView resets its content in order to reflect the changes. You can solve the issue by disabling animations during the update process. Here is a sample:
string selectedNode = "";
if (this.radTreeView1.SelectedNode != null)
{
    selectedNode = this.radTreeView1.SelectedNode.Value.ToString();
}
 
string hoveredNode = "";
foreach (TreeNodeElement nodeElement in this.radTreeView1.TreeViewElement.ViewElement.Children)
{
    if (nodeElement.HotTracking)
    {
        hoveredNode = nodeElement.Data.Value.ToString();
        break;
    }
}
 
ThemeResolutionService.AllowAnimations = false;
             
this.radTreeView1.DataSource = t;
this.radTreeView1.ExpandAll();
 
if (!string.IsNullOrEmpty(selectedNode))
{
    RadTreeNode[] nodes = this.radTreeView1.FindNodes(selectedNode);
    if (nodes.Length > 0)
    {
        this.radTreeView1.SelectedNode = nodes[0];
    }
}
 
if (!string.IsNullOrEmpty(hoveredNode))
{
    RadTreeNode[] nodes = this.radTreeView1.FindNodes(hoveredNode);
    if (nodes.Length > 0)
    {
        TreeNodeElement nodeElement = this.radTreeView1.TreeViewElement.GetElement(nodes[0]);
        if (nodeElement != null)
        {
            nodeElement.SetValue(TreeNodeElement.HotTrackingProperty, true);
        }
    }
}
 
Application.DoEvents();
ThemeResolutionService.AllowAnimations = true;

I hope this helps.
 
Kind regards,
Jack
the Telerik team

Q2’11 SP1 of RadControls for WinForms is available for download (see what's new); also available is the Q3'11 Roadmap for Telerik Windows Forms controls.

Tags
Treeview
Asked by
Mark
Top achievements
Rank 1
Answers by
Jack
Telerik team
Share this question
or