We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy.
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

Using keyboard to expand nodes

Thread ID:

Created:

Updated:

Platform:

Replies:

123993 May 5,2016 07:10 PM UTC May 9,2016 04:05 AM UTC WPF 4
loading
Tags: GridTreeControl
Craig Greenway
Asked On May 5, 2016 07:10 PM UTC

Hi, I was surprised that the GridTree didn't expand nodes when pressing the Right arrow key on the keyboard.  I was happy with the keyboard behaviour for up and down to move between expanded nodes only, but I can't see any instructions on how to expand nodes using the keyboard.  Please could you point me in the right direction?

Jai Ganesh S [Syncfusion]
Replied On May 6, 2016 10:17 AM UTC

Hi Craig, 
 
You can achieve your requirement by using the PreviewKeydown event like below, 
 
treeGrid.PreviewKeyDown += treeGrid_PreviewKeyDown; 
 
void treeGrid_PreviewKeyDown(object sender, KeyEventArgs e) 
  { 
            var node = this.treeGrid.SelectedNode as GridTreeNode; 
 
            if (node == null) 
                return; 
 
            if (node.ParentNode == null && e.Key == Key.Right) 
            { 
                treeGrid.InternalGrid.ExpandNode(node); 
                 
                e.Handled = true; 
            } 
            else if (node.ParentNode == null && e.Key == Key.Left) 
            { 
                treeGrid.InternalGrid.CollapseNode(node); 
            } 
 
            treeGrid.InternalGrid.ResetDisplay(); 
 
   } 
 
 
Regards, 
Jai Ganesh S 


Craig Greenway
Replied On May 6, 2016 12:27 PM UTC

Thank you, if you have a few levels of nodes, rather than checking ParentNode is there a HasChildren or similar property?

Craig Greenway
Replied On May 6, 2016 05:40 PM UTC

Thank you, if you have a few levels of nodes, rather than checking ParentNode is there a HasChildren or similar property?

Sorry found what I needed, here's my code for other people:

        private void treeGrid_OnPreviewKeyDown(object sender, KeyEventArgs e)
        {
            var node = this.treeGrid.SelectedNode as GridTreeNode;
           
            if (node == null)
                return;       

            if (node.HasChildNodes && e.Key == Key.Right)
            {
                treeGrid.InternalGrid.ExpandNode(node);
                e.Handled = true;
            }
            else if (node.HasChildNodes && e.Key == Key.Left)
            {
                treeGrid.InternalGrid.CollapseNode(node);
                e.Handled = true;
            }
            else if (e.Key == Key.Right || e.Key == Key.Left)
            {
                e.Handled = true;
            }

            treeGrid.InternalGrid.ResetDisplay();
        }

Jai Ganesh S [Syncfusion]
Replied On May 9, 2016 04:05 AM UTC

Hi Craig, 
 
Thank you for the update. 
 
Please let us know if you need further assistance on this. 
 
Regards, 
Jai Ganesh S 


CONFIRMATION

This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

Warning Icon You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.Close Icon

;