Spread Windows Forms 12.0 Product Documentation
Changing an Input Map for a Child View
Spread Windows Forms 12.0 Product Documentation > Developer's Guide > Managing Keyboard Interaction > Changing an Input Map for a Child View

Normally, when you change an input map definition, it applies only to inputs in the active sheet. For a hierarchical display, this only applies to the parent sheet and not to any expanded child sheets of the hierarchy. Spread treats the parent and each child as different workbooks. If you want to change input maps for child parts of a hierarchy, you need to implement the ChildWorkbookCreated event which occurs when the child workbooks are created. Then you can change the input maps for those child workbooks.

Hiearchy with child view

Using Code

  1. Create an InputMap object.
  2. Use the GetInputMap method.
  3. Use the Put method.
  4. Create a data set.

Example

This example shows how to change an input map for a parent, then expand a hierarchical display and change the input map for a child of that hierarchy.

C#
Copy Code
 private void Form1_Load(object sender, System.EventArgs e) {
   // Change input maps for Enter key in parent hierarchies.
   FarPoint.Win.Spread.InputMap im = new FarPoint.Win.Spread.InputMap();
   im = fpSpread1.GetInputMap(FarPoint.Win.Spread.InputMapMode.WhenFocused);
   im.Put(new FarPoint.Win.Spread.Keystroke(Keys.Enter, Keys.None), FarPoint.Win.Spread.SpreadActions.MoveToNextRow);
   im = fpSpread1.GetInputMap(FarPoint.Win.Spread.InputMapMode.WhenAncestorOfFocused);
im.Put(new FarPoint.Win.Spread.Keystroke(Keys.Enter, Keys.None), FarPoint.Win.Spread.SpreadActions.MoveToNextRow);
   
   DataSet ds = new DataSet();
   DataTable fpParent = new DataTable();
   DataTable fpChild1 = new DataTable();
   
   fpParent = ds.Tables.Add("SAMPLE");
   fpParent.Columns.AddRange(new DataColumn[] {new DataColumn("Column1", Type.GetType("System.String")), new DataColumn("Column2", Type.GetType("System.Int32"))});
   fpParent.Rows.Add(new object[] {"Parent1", 0});
   fpParent.Rows.Add(new object[] {"Parent2", 1});
   
   fpChild1 = ds.Tables.Add("Child1");
   fpChild1.Columns.AddRange(new DataColumn[] {new
  DataColumn("Column1", Type.GetType("System.String")), new DataColumn("Column2", Type.GetType("System.Int32"))});
   fpChild1.Rows.Add(new object[] {"Child1-1", 0});
   fpChild1.Rows.Add(new object[] {"Child1-2", 0});
   fpChild1.Rows.Add(new object[] {"Child1-3", 0});
   fpChild1.Rows.Add(new object[] {"Child2-1", 1});
   fpChild1.Rows.Add(new object[] {"Child2-2", 1});
   fpChild1.Rows.Add(new object[] {"Child2-3", 1});
   
   ds.Relations.Add("Relation1", fpParent.Columns["Column2"], fpChild1.Columns["Column2"]);
   fpSpread1.ActiveSheet.DataSource = ds;
   
   // Expand child hierarchies.
   fpSpread1.ActiveSheet.ExpandRow(0, true);
   fpSpread1.ActiveSheet.ExpandRow(1, true);
 }
 private void fpSpread1_ChildWorkbookCreated(object sender, FarPoint.Win.Spread.ChildWorkbookCreatedEventArgs e)
 {
   // Change its input map for Enter key in child hierarchies (e.Workbook: the target is child SpreadView).
   FarPoint.Win.Spread.InputMap im = new FarPoint.Win.Spread.InputMap();
   
   im = e.Workbook.GetInputMap(FarPoint.Win.Spread.InputMapMode.WhenFocused);
   im.Put(new FarPoint.Win.Spread.Keystroke(Keys.Enter, Keys.None), FarPoint.Win.Spread.SpreadActions.MoveToNextRow);
   im = e.Workbook.GetInputMap(FarPoint.Win.Spread.InputMapMode.WhenAncestorOfFocused);
   im.Put(new FarPoint.Win.Spread.Keystroke(Keys.Enter, Keys.None), FarPoint.Win.Spread.SpreadActions.MoveToNextRow);
 }
VB
Copy Code
 Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Load
   
   ' Change input maps for Enter key in parent hierarchies.
   Dim im As New FarPoint.Win.Spread.InputMap
   im = fpSpread1.GetInputMap(FarPoint.Win.Spread.InputMapMode.WhenFocused)   im.Put(New FarPoint.Win.Spread.Keystroke(Keys.Enter, Keys.None), FarPoint.Win.Spread.SpreadActions.MoveToNextRow)
   im = fpSpread1.GetInputMap(FarPoint.Win.Spread.InputMapMode.WhenAncestorOfFocused)   im.Put(New FarPoint.Win.Spread.Keystroke(Keys.Enter, Keys.None), FarPoint.Win.Spread.SpreadActions.MoveToNextRow)
   
   Dim ds As New DataSet
   Dim fpParent As DataTable
   Dim fpChild1 As DataTable
   fpParent = ds.Tables.Add("SAMPLE")
   fpParent.Columns.AddRange(New DataColumn() {New DataColumn("Column1", Type.GetType("System.String")), New DataColumn("Column2", Type.GetType("System.Int32"))})
   fpParent.Rows.Add(New Object() {"Parent1", 0})
   fpParent.Rows.Add(New Object() {"Parent2", 1})
   
   fpChild1 = ds.Tables.Add("Child1")
   fpChild1.Columns.AddRange(New DataColumn() {New DataColumn("Column1", Type.GetType("System.String")), New DataColumn("Column2", Type.GetType("System.Int32"))})
   fpChild1.Rows.Add(New Object() {"Child1-1", 0})
   fpChild1.Rows.Add(New Object() {"Child1-2", 0})
   fpChild1.Rows.Add(New Object() {"Child1-3", 0})
   fpChild1.Rows.Add(New Object() {"Child2-1", 1})
   fpChild1.Rows.Add(New Object() {"Child2-2", 1})
   fpChild1.Rows.Add(New Object() {"Child2-3", 1})
   
   ds.Relations.Add("Relation1", fpParent.Columns("Column2"), fpChild1.Columns("Column2"))
fpSpread1.ActiveSheet.DataSource = ds
   
   ' Expand child hierarchies.
   fpSpread1.ActiveSheet.ExpandRow(0, True)
   fpSpread1.ActiveSheet.ExpandRow(1, True)
 End Sub

 Private Sub fpSpread1_ChildWorkbookCreated(ByVal sender As Object, ByVal e As FarPoint.Win.Spread.ChildWorkbookCreatedEventArgs) Handles FpSpread1.ChildWorkbookCreated
   ' Change its input map for Enter key in child hierarchies (e.Workbook: the target is child SpreadView).
   Dim im As New FarPoint.Win.Spread.InputMap
   im = e.Workbook.GetInputMap(FarPoint.Win.Spread.InputMapMode.WhenFocused)   im.Put(New FarPoint.Win.Spread.Keystroke(Keys.Enter, Keys.None), FarPoint.Win.Spread.SpreadActions.MoveToNextRow)
   im = e.Workbook.GetInputMap(FarPoint.Win.Spread.InputMapMode.WhenAncestorOfFocused) im.Put(New FarPoint.Win.Spread.Keystroke(Keys.Enter, Keys.None), FarPoint.Win.Spread.SpreadActions.MoveToNextRow)
 End Sub
See Also