New to Telerik UI for WinFormsStart a free 30-day trial

Manually handle up/down keys in RadTreeView

Updated over 6 months ago

Environment

Product Version2018.3.911
ProductRadTreeView for WinForms

Description

It is a common case to override or customize the navigation or other keys that have a specific built-in function. The bellow example shows how you can handle the up/down keys manually.

Solution

To achieve this you need to create a custom RadTreeViewElement and override the ProcessKeyDown method.

C#
class MyTreeView : RadTreeView
{
    protected override RadTreeViewElement CreateTreeViewElement()
    {
        return new MyThreeViewElement();
    }
    public override string ThemeClassName
    {
        get
        {
            return typeof(RadTreeView).FullName;
        }
    }
}
class MyThreeViewElement : RadTreeViewElement
{
    protected override bool ProcessKeyDown(KeyEventArgs e)
    {
        if (e.KeyCode == Keys.Up)
        {
            //select your node here
            return true;
        }
        else if (e.KeyCode == Keys.Down)
        {
            //select your node here
            return true;
        }
        return base.ProcessKeyDown(e);
    }
    protected override Type ThemeEffectiveType
    {
        get { return typeof(RadTreeViewElement); }
    }
}
In this article
EnvironmentDescriptionSolution
Not finding the help you need?
Contact Support