Skip Navigation LinksHome / Community & Support / Developer Productivity Tools Forums / WinForms > Treeview > Maintain selection after setting datasource

Not answered Maintain selection after setting datasource

Feed from this thread
  • Mark avatar

    Posted on Nov 2, 2011 (permalink)

    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!

    Reply

  • Jack Jack admin's avatar

    Posted on Nov 7, 2011 (permalink)

    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.

    Reply

Back to Top

Skip Navigation LinksHome / Community & Support / Developer Productivity Tools Forums / WinForms > Treeview > Maintain selection after setting datasource
Related resources for "Maintain selection after setting datasource"

[ Features | Demos | Documentation | Knowledge Base | Telerik TV | Code Library | Step-by-step Tutorial | Blogs | Self-Paced Trainer ]