TreeView.SelectedNodeChanging have e.Action equivalent?

2 posts, 0 answers
  1. Ron Weingarten
    Ron Weingarten avatar
    5 posts
    Member since:
    May 2010

    Posted 13 Nov 2013 Link to this post

    In the Windows TreeView, in the BeforeSelect event, the TreeViewCancelEventArgs has a property called Action. So I can check e.Action, and if the source of the action is code, or user input, I can take the appropriate action.

    The closest thing RadTreeView has for this event is SelectedNodeChanging. However, the RadTreeViewCancelEventArgs doesn't have an Action property. When using a RadTreeView and handling the SelectedNodeChanging event, how can I determine the source of the selection change, whether by code or user input?
  2. Dess
    Admin
    Dess avatar
    1609 posts

    Posted 18 Nov 2013 Link to this post

    Hello Ron,

    Thank you for contacting Telerik Support.

    RadTreeView does not support action indication during selection changing. However, this would be very useful and I have logged it as a Feature request in our Public Issue Tracking System - PITS. You can track its progress, subscribe for status changes and add your vote/comment to it on the following link - Feature request.

    I have also updated your Telerik points

    Currently, the possible workaround that I can propose is to handle if the mouse button is clicked or some of the arrow keys are pressed:
    bool upDownArrowsPress = false;
     
    public Form1()
    {
        InitializeComponent();
     
        radTreeView1.SelectedNodeChanging += radTreeView1_SelectedNodeChanging;
        radTreeView1.PreviewKeyDown += radTreeView1_PreviewKeyDown;
        radTreeView1.SelectedNodeChanged += radTreeView1_SelectedNodeChanged;
    }

    public enum Action
    {
        Keyboard,
        Mouse,
        Unknown
    }
     
    private void radTreeView1_SelectedNodeChanged(object sender, RadTreeViewEventArgs e)
    {
        upDownArrowsPress = false;
    }
     
    private void radTreeView1_PreviewKeyDown(object sender, PreviewKeyDownEventArgs e)
    {
        if (e.KeyCode == Keys.Up || e.KeyCode == Keys.Down || e.KeyCode == Keys.Left || e.KeyCode == Keys.Right)
        {
            upDownArrowsPress = true;
        }
    }
     
    private void radTreeView1_SelectedNodeChanging(object sender, Telerik.WinControls.UI.RadTreeViewCancelEventArgs e)
    {
        Action action;
        RadTreeViewElement tree = sender as RadTreeViewElement;
        
        if (Control.MouseButtons != System.Windows.Forms.MouseButtons.None)
        {
            action = Action.Mouse;
        }
        else if (upDownArrowsPress)
        {
            action = Action.Keyboard;
        }
        else
        {
            action = Action.Unknown;
        }
     
    }

    I hope this information helps. Should you have further questions, I would be glad to help.

    Regards,
    Desislava
    Telerik
    TRY TELERIK'S NEWEST PRODUCT - EQATEC APPLICATION ANALYTICS for WINFORMS.
    Learn what features your users use (or don't use) in your application. Know your audience. Target it better. Develop wisely.
    Sign up for Free application insights >>
  3. UI for WinForms is Visual Studio 2017 Ready
Back to Top