Selecting a node on Mouse Right Click

Posted by: Swapnil.Walwadkar on 15 November 2017, 3:12 pm EST

    • Post Options:
    • Link

    Posted 15 November 2017, 3:12 pm EST

    Hello,

    I am using C1 Treeview in my project.

    Is there any way to select a node on Mouse Right Click? Actually I am invoking Context Menu on Right Click but before that it should select the node first and then invoke Context Menu.

  • Posted 15 November 2017, 3:52 pm EST

    Hi,

    Try to use the below code in MouseRightButtonDown event;

            private void C1TreeView_MouseRightButtonDown(object sender, MouseButtonEventArgs e)
            {           
                Point p = e.GetPosition(treeview);
                var ControlType = treeview.InputHitTest(p);
                if (!(ControlType is Border))
                {
                    var node = treeview.GetNode(p);
                    node.IsSelected = true;
                }
            }
    

    Hope, it will solve your issue.

    Thanks,

    Singh

  • Posted 18 November 2017, 1:51 pm EST

    Thank you for your valuable response.

    Is there any alternate way to do this and stick with MVVM Pattern? Event Trigger? Or anything else?

  • Posted 19 November 2017, 6:07 pm EST

    Hi,

    You can set you MVVM property in MouseRightButtonDown event as below:

    private void C1TreeView_MouseRightButtonDown(object sender, MouseButtonEventArgs e)
            {           
                Point p = e.GetPosition(treeview);
                var ControlType = treeview.InputHitTest(p);
                if (!(ControlType is Border))
                {
                    var node = treeview.GetNode(p);
                    node.IsSelected = true;
                    dataitems.MySelectedItem = node.DataContext as Item;   // Set MVVM property here
                }
            }
    

    Also, find a sample application attached.

    Note: You can modify attached sample accordingly.

    Thanks,

    Singh

    TreeViewRightMouseSelect.zip

Need extra support?

Upgrade your support plan and get personal unlimited phone support with our customer engagement team

Learn More

Forum Channels