Spread Windows Forms and Hierarchy Navigation

Spread for Windows Forms can display relational data, such as from a relational database, in hierarchical views. The following image displays a typical hierarchical view with expanded child sheets. SpreadWinHier Hierarchy The top-level hierarchical view is displayed in a parent sheet. Child records are displayed in separate, child sheets. This can make navigating with keyboard keys from one sheet to another difficult. You can write code that allows you to navigate through the rows in the parent and child sheets. The sample project included at the end of this blog allows you to use up or down arrow keys to navigate through the parent and child rows. The following code from the sample creates custom action maps that move to the previous row (up arrow) or to the next row (down arrow).

fpSpread1.GetActionMap().Put("HierarchyMoveToPreviousRow", new HierarchyMoveToPreviousRowAction());  
fpSpread1.GetActionMap().Put("HierarchyMoveToNextRow", new HierarchyMoveToNextRowAction());  
InputMap inputMap = fpSpread1.GetInputMap(InputMapMode.WhenFocused);  
inputMap.Put(new Keystroke(Keys.Up, Keys.None), "HierarchyMoveToPreviousRow");  
inputMap.Put(new Keystroke(Keys.Down, Keys.None), "HierarchyMoveToNextRow");

This code from the example binds Spread to a datasource using a CreateDataSource function.

fpSpread1.DataSource = CreateDataSource();

This code from the example uses a function to expand all the child sheets so that navigation works properly.


The input maps are set for the parent sheet and all the child sheets in this section of code.

SpreadView root = fpSpread1.GetRootWorkbook();  
      foreach (SpreadView child in root.GetChildWorkbooks())  
        SetInputMapRecursive(inputMap, root, child);

You can get the complete Visual Studio 2015 C# or VB sample project from this location: C# SpreadCustomActionsSample VB SpreadCustomActionsSampleVB


GrapeCity Developer Tools
comments powered by Disqus