MSHFlex Grid[Visual Basic 6.0] control is a goog tool for showing data in a tabular format as in Excel.
Data entry in Grid also possible with a Text Box which require handling Keyup,KeyPress Events of the TextBox control.
Place a GridControl and a TextBox to your project and add the following code the Textbox Events.
Public Sub MCellEnter()
With MSHFlexGrid_POrder
txt_DEntry.Text = .TextMatrix(.row, .col)
txt_DEntry.Move (.CellLeft + .Left), (.CellTop + .Top), _
.CellWidth, .CellHeight
txt_DEntry.Visible = True
DoEvents
txt_DEntry.SetFocus
End With
End Sub
The above code place the text box on the active cell by adjusting hight, width and top of Text Box
Private Sub txt_DEntry_KeyPress(KeyAscii As Integer)
If KeyAscii = 13 Then
With MSHFlexGrid_POrder
.TextMatrix(.row, .col) = txt_DEntry
If .col < .Cols – 1 Then
.col = .col + 1
MCellEnter
Else
.col = 0
If (.row + 1) < .Rows Then
.row = .row + 1
End If
MCellEnter
End IfEnd With
End IfEnd Sub
The above code handle the enter keybehaviour and following keep track of Arrow key movements.
Private Sub txt_DEntry_KeyDown(KeyCode As Integer, Shift As Integer)
With MSHFlexGrid_POrder
.Refresh
.TextMatrix(.row, .col) = txt_DEntrySelect Case KeyCode
Case KeyCodeConstants.vbKeyDown
If .row + 1 < .Rows Then
.row = .row + 1
MCellEnter
End If
Case KeyCodeConstants.vbKeyUp
If (.row – 1) > 0 Then
.row = .row – 1
MCellEnter
End If
Case KeyCodeConstants.vbKeyRight
If (.col + 1 < .Cols) Then
.col = .col + 1
MCellEnter
End If
Case KeyCodeConstants.vbKeyLeft
If (.col – 1) >= 0 Then
.col = .col – 1
MCellEnter
End If
End Select
End WithEnd Sub
That’s all you need to know