Home DevExpress Tips How to Easily Navigate the DevExpress XtraTreeList With Right Left Keyboard Key
Author:

The default keyboard navigation setting for the XtraTreeList control is to hold the Control key with the left or right key to navigate the treelist.
 Hold Control + Left to expand the node
 Hold Control + Right to collapse the node
 
To change this default behaviour so that you can use the right or left arrow key to navigate the treelist without having to hold the Control key, you will need to implement the TreeList.KeyDown event and insert the below code.

protected internal void tlFuncLoc_KeyDown(object sender, KeyEventArgs e)

{

    TreeList tl = sender as TreeList;

    if (tl.FocusedNode == null) return;

    if (e.Control)

    {

        if (tl.FocusedColumn == null) return;

        int idx = tl.FocusedColumn.VisibleIndex;

        if (e.KeyCode == Keys.Left)

        {

            if (idx > 0)

                tl.FocusedColumn = tl.GetColumnByVisibleIndex(idx - 1);

            e.Handled = true;

        }

        else if (e.KeyCode == Keys.Right)

        {

            DevExpress.XtraTreeList.Columns.TreeListColumn col = tl.GetColumnByVisibleIndex(idx + 1);

            if (col != null)

                tl.FocusedColumn = col;

            e.Handled = true;

        }

    }

    else

    {

        if (e.KeyCode == Keys.Left)

        {

            tl.FocusedNode.Expanded = false;

            e.Handled = true;

        }

        else if (e.KeyCode == Keys.Right)

        {

            tl.FocusedNode.Expanded = true;

            e.Handled = true;

        }

    }

}



Comments (0)
Write comment
Your Contact Details:
Comment:
Security
Please input the anti-spam code that you can read in the image.

"