Form1.vb
-------------------------- Imports FarPoint.Win.Spread
- Imports FarPoint.Win.Spread.CellType
- Public Class Form1
- Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
- FpSpread1_Sheet1.ColumnCount = 6
- SetSpreadInputMap()
- SetListBox()
- End Sub
- Private Sub SetSpreadInputMap()
- Dim oMap As InputMap
- oMap = FpSpread1.GetInputMap(InputMapMode.WhenFocused)
- oMap.Put(New Keystroke(Keys.Enter, Keys.None), SpreadActions.MoveToNextColumnWrap)
- oMap.Put(New Keystroke(Keys.Enter, Keys.Shift), SpreadActions.MoveToPreviousColumnWrap)
- oMap = FpSpread1.GetInputMap(InputMapMode.WhenAncestorOfFocused)
- oMap.Put(New Keystroke(Keys.F2, Keys.None), SpreadActions.None)
- oMap.Put(New Keystroke(Keys.F3, Keys.None), SpreadActions.None)
- oMap.Put(New Keystroke(Keys.F4, Keys.None), SpreadActions.None)
- oMap.Put(New Keystroke(Keys.Tab, Keys.None), SpreadActions.None)
- oMap.Put(New Keystroke(Keys.Tab, Keys.Shift), SpreadActions.None)
- oMap.Put(New Keystroke(Keys.Enter, Keys.None), SpreadActions.MoveToNextColumnWrap)
- oMap.Put(New Keystroke(Keys.Enter, Keys.Shift), SpreadActions.MoveToPreviousColumnWrap)
- oMap.Put(New Keystroke(Keys.Left, Keys.None), SpreadActions.MoveToPreviousColumnWrap)
- oMap.Put(New Keystroke(Keys.Right, Keys.None), SpreadActions.MoveToNextColumnWrap)
- End Sub
- Private Sub SetListBox()
- Dim oListBox1 As New ListBox()
- oListBox1.Items.Add("")
- oListBox1.Items.Add("B1")
- oListBox1.Items.Add("B2")
- Dim oListBox3 As New ListBox()
- oListBox3.Items.Add("")
- oListBox3.Items.Add("A1")
- oListBox3.Items.Add("A2")
- oListBox3.Items.Add("A3")
- oListBox3.Items.Add("A4")
- Dim ct1 As ComboBoxCellType = CType(FpSpread1.Sheets(0).Columns(1).CellType, ComboBoxCellType)
- Dim ct3 As ComboBoxCellType = CType(FpSpread1.Sheets(0).Columns(3).CellType, ComboBoxCellType)
- ct1.ListControl = oListBox1
- ct3.ListControl = oListBox3
- AddHandler oListBox1.KeyDown, AddressOf pCellKeyDown
- AddHandler oListBox3.KeyDown, AddressOf pCellKeyDown
- End Sub
- Private Sub pCellKeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs)
- If e.KeyCode = Keys.Enter Then
- FpSpread1.StopCellEditing()
- SendKeys.Send("{Enter}")
- End If
- End Sub
- Private Sub FpSpread1_EnterCell(ByVal sender As Object, ByVal e As FarPoint.Win.Spread.EnterCellEventArgs) Handles FpSpread1.EnterCell
- Select Case e.Column
- Case 1
- FpSpread1.EditMode = True
- Case 3
- FpSpread1.EditMode = True
- Case Else
- FpSpread1.EditMode = True
- End Select
- End Sub
- Private Sub FpSpread1_Sheet1_CellChanged(ByVal sender As Object, ByVal e As FarPoint.Win.Spread.SheetViewEventArgs) Handles FpSpread1_Sheet1.CellChanged
- Select Case e.Column
- Case 0
- Dim value As Integer = IIf(FpSpread1_Sheet1.Cells(e.Row, e.Column).Text = "", 0, CInt(FpSpread1_Sheet1.Cells(e.Row, e.Column).Text))
- FpSpread1_Sheet1.Cells(e.Row, 1).Value = value
- Case 2
- Dim value As Integer = IIf(FpSpread1_Sheet1.Cells(e.Row, e.Column).Text = "", 0, CInt(FpSpread1_Sheet1.Cells(e.Row, e.Column).Text))
- FpSpread1_Sheet1.Cells(e.Row, 3).Value = value
- End Select
- End Sub
- End Class
复制代码 |