Node Hittest only on Node direkt

2 posts, 1 answers
  1. Christian
    Christian avatar
    22 posts
    Member since:
    May 2012

    Posted 07 Feb Link to this post

    Hallo,

    is there any way to only get a direkt right click on a node? The GetElementAtPoint get's the node even if the cursor is outside of the (visible part) of the node but at the same hight (I think this is the same reason why the hottrack reacts outside of the visible part of the node)

    I'd use the NodeMouseClick but the event args aren't derived from MouseEventArgs so there is no MousePosition/MouseButton (I think this should be changed)

    private void radTreeView1_MouseDown(object sender, MouseEventArgs e)
    {
        if (e.Button == System.Windows.Forms.MouseButtons.Right)
        {
            TreeNodeElement el = radTreeView1.ElementTree.GetElementAtPoint(e.Location) as TreeNodeElement;
            ...
        }
    }

     

    So I need to distinguish between a direkt right click on a node and a right click on the treeview (the white part)

  2. Answer
    Hristo
    Admin
    Hristo avatar
    1028 posts

    Posted 07 Feb Link to this post

    Hi Christian,

    Thank you for writing.

    The text part of the node is actually located in a TreeNodeContentElement. In order to be notified when a click has been performed on it, you would need to extend the MouseDown event handler this way:
    private void radTreeView1_MouseDown(object sender, MouseEventArgs e)
    {
        if (e.Button == System.Windows.Forms.MouseButtons.Right)
        {
            TreeNodeElement el = radTreeView1.ElementTree.GetElementAtPoint(e.Location) as TreeNodeElement;
            if (el!= null)
            {
                TreeNodeContentElement contentElement = el.FindDescendant<TreeNodeContentElement>();
                if (contentElement != null && contentElement.IsMouseOverElement)
                {
                    RadMessageBox.Show("ContentElement " + contentElement.Text + " clicked!");
                }
            }
        }
    }

    I hope this helps. Should you have further questions please do not hesitate to write back.

    Regards,
    Hristo
    Telerik by Progress
    Try our brand new, jQuery-free Angular 2 components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
Back to Top