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

Node Hittest only on Node direkt

1 Answer 83 Views
Treeview
This is a migrated thread and some comments may be shown as answers.
Christian
Top achievements
Rank 1
Christian asked on 07 Feb 2017, 07:35 AM

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)

1 Answer, 1 is accepted

Sort by
0
Accepted
Hristo
Telerik team
answered on 07 Feb 2017, 11:22 AM
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.
Tags
Treeview
Asked by
Christian
Top achievements
Rank 1
Answers by
Hristo
Telerik team
Share this question
or