Q1 2011 breaking changes

4 posts, 1 answers
  1. Zensell
    Zensell avatar
    12 posts
    Member since:
    Jul 2009

    Posted 17 Mar 2011 Link to this post

    Hi, how should I fix these breaking changes?

    - CompareNodesTagCommand has been removed.
    - RadTreeNodeCollection.Find has been removed.
    - RadTreeNode.DataBoundItem is read-only. Is there a way to change it manually in unbound mode?
    - TreeNodeUI has been removed.

    Thanks.
  2. Answer
    Julian Benkov
    Admin
    Julian Benkov avatar
    1135 posts

    Posted 22 Mar 2011 Link to this post

    Hello Zensell,

    1) You can use new Find method of RadTreeView control for this behavior. Here is a small example:

    private object tagKey;
    private bool FindByTag(RadTreeNode node)
    {
        if (node.Tag != null)
        {
            IComparable comparer = node.Tag as IComparable;
            if ((comparer != null && comparer.CompareTo(tagKey) == 0) ||
                node.Tag.Equals(key))
            {
                return true;
            }
        }
     
        return false;
    }
     
     
    private void radButton1_Click(object sender, EventArgs e)
    {
        RadTreeNode nodeByTag = this.radTreeView1.Find(this.FindByTag);
    }

    If you want to use the old Command aproach here is implementation of removed CompareNodesTagCommand command:
    public class CompareNodesTagCommand : CommandBase
    {
        public override object Execute(params object[] settings)
        {
            if (settings.Length > 1 &&
                this.CanExecute(settings[0]))
            {
                RadTreeNode node = settings[0] as RadTreeNode;
                object key = (settings[1] as IList)[0];
     
                if (node != null && node.Tag != null)
                {
                    IComparable comparer = node.Tag as IComparable;
                    if ((comparer != null && comparer.CompareTo(key) == 0) ||
                        node.Tag.Equals(key))
                    {
                        return node;
                    }
                }
            }
            return null;
        }
     
        public override bool CanExecute(object parameter)
        {
            if (typeof(RadTreeNode).IsAssignableFrom(parameter.GetType()))
            {
                return true;
            }
            return base.CanExecute(parameter);
        }
    }


    2) The new Find command can be used implementing a different search callback function:
    private void radButton1_Click(object sender, EventArgs e)
    {
        RadTreeNode nodeByName = this.radTreeView1.Find(this.FindByKey);
        RadTreeNode nodeByText = this.radTreeView1.Find(this.FindByText);
    }
     
    private string key;
    private bool FindByKey(RadTreeNode node)
    {
        if ((this.key == null) || (node.Name == null))
        {
            return false;
        }
     
        if (this.key.Length != node.Name.Length)
        {
            return false;
        }
     
        return (string.Compare(this.key, node.Name, true, CultureInfo.InvariantCulture) == 0);
    }
     
    private string text;
    private bool FindByText(RadTreeNode node)
    {
        if ((this.text == null) || (node.Text == null))
        {
            return false;
        }
     
        if (this.text.Length != node.Text.Length)
        {
            return false;
        }
     
        return (string.Compare(this.text, node.Text, true, CultureInfo.InvariantCulture) == 0);
    }

    3) DataBoundItem is used only in bound mode and can not be changed at run time. You can use the Tag property to reference your custom business object related to RadTreeNode object.

    4) TreeNodeUI element is changed with TreeNodeElement that supports full customization. More information you can refer in our online documentation or in our Examples application, section TreeView >> Customize.

    All the best,
    Julian Benkov
    the Telerik team
  3. UI for WinForms is Visual Studio 2017 Ready
  4. MP
    MP avatar
    22 posts
    Member since:
    May 2009

    Posted 25 May 2011 Link to this post

    Dear Telerik,

    We were using the TreeNodeUI.AssociatedNode property and now are not sure how to access this property with the new release. We had used the following code to find out which node was being double-clicked. Please advise.

    foreach (TreeNodeUI treeNodeUI in this.radTreeView1.TreeViewElement.Items)
    {
        if (treeNodeUI.AssociatedTreeNode == radTreeView1.SelectedNode)
        {
            uiNode = treeNodeUI;
            break;
        }
    }
    if (uiNode != null)
    {
        if (uiNode.BoundingRectangle.Contains(e.Location))
        {   

            //do stuff

     

          }
    }

  5. Julian Benkov
    Admin
    Julian Benkov avatar
    1135 posts

    Posted 28 May 2011 Link to this post

    Hello MP,

    For this scenario you can use following code snippet:

    TreeNodeElement nodeElement = this.radTreeView1.TreeViewElement.GetElement(this.radTreeView1.SelectedNode);
    if (nodeElement != null && nodeElement.BoundingRectangle.Contains(e.Location))
    {
        //TO DO
    }

    Do not hesitate to contact us if you have further questions or issues.

    Best wishes,
    Julian Benkov
    the Telerik team
    Q1’11 SP1 of RadControls for WinForms is available for download; also available is the Q2'11 Roadmap for Telerik Windows Forms controls.
Back to Top