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

TreeView.SelectedNodeChanging have e.Action equivalent?

1 Answer 45 Views
Treeview
This is a migrated thread and some comments may be shown as answers.
Ron Weingarten
Top achievements
Rank 1
Ron Weingarten asked on 14 Nov 2013, 12:42 AM
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?

1 Answer, 1 is accepted

Sort by
0
Dess | Tech Support Engineer, Principal
Telerik team
answered on 18 Nov 2013, 03:57 PM
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 >>
Tags
Treeview
Asked by
Ron Weingarten
Top achievements
Rank 1
Answers by
Dess | Tech Support Engineer, Principal
Telerik team
Share this question
or