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. Image for the cookie policy date

Using keyboard to expand nodes

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?

4 Replies

JG Jai Ganesh S Syncfusion Team 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 



CG Craig Greenway 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?


CG Craig Greenway replied to Craig Greenway 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();
        }


JG Jai Ganesh S Syncfusion Team 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 


Loader.
Up arrow icon