Maintain selection after setting datasource

2 posts, 0 answers
  1. Mark
    Mark avatar
    4 posts
    Member since:
    Aug 2011

    Posted 02 Nov 2011 Link to this post


    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!
  2. Jack
    Jack avatar
    2335 posts

    Posted 07 Nov 2011 Link to this post

    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();
    ThemeResolutionService.AllowAnimations = false;
    this.radTreeView1.DataSource = t;
    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);
    ThemeResolutionService.AllowAnimations = true;

    I hope this helps.
    Kind regards,
    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.

  3. DevCraft banner
Back to Top