I changed a working VB 6 program to use ADO and MSHFlexGrid(OLE). I have a text box to allow entry into the grid of the number of copies to print of a certain invoice. The problem is that the number entered into the text box doesn't show as it is keyed, only after leaving the cell. Here is my code:
Private Sub MSHFlexGrid1_Click()
If MSHFlexGrid1.Col = 3 Then
With MSHFlexGrid1
txtDataEntry.Text = .TextMatrix(.Row, .Col)
txtDataEntry.Move .CellLeft + .Left, .CellTop+
.Top, .CellWidth, .CellHeight
txtDataEntry.Visible = True
DoEvents
txtDataEntry.SetFocus
End With
End If
End Sub
Private Sub MSHFlexGrid1_GotFocus()
Call SaveEdits
End Sub
Private Sub MSHFlexGrid1_KeyPress(KeyAscii As Integer)
If MSHFlexGrid1.Col = 3 Then
Select Case KeyAscii
Case 48 To 57
txtDataEntry.Text = Chr$(KeyAscii)
txtDataEntry.SelStart = 1
End Select
With MSHFlexGrid1
txtDataEntry.Move .CellLeft + .Left, .CellTop + .Top, .CellWidth, .CellHeight
txtDataEntry.Visible = True
DoEvents
txtDataEntry.SetFocus
End With
End If
End Sub
Private Sub MSHFlexGrid1_LeaveCell()
Call SaveEdits
End Sub
Private Sub txtDataEntry_KeyPress(KeyAscii As Integer)
Select Case KeyAscii
Case 48 To 57
Case Else
KeyAscii = 0
End Select
End Sub
Private Sub SaveEdits()
If Not (txtDataEntry.Visible) Then Exit Sub
MSHFlexGrid1.TextMatrix(MSHFlexGrid1.Row, MSHFlexGrid1.Col) = txtDataEntry.Text
txtDataEntry.Visible = False
End Sub
Private Sub MSHFlexGrid1_Click()
If MSHFlexGrid1.Col = 3 Then
With MSHFlexGrid1
txtDataEntry.Text = .TextMatrix(.Row, .Col)
txtDataEntry.Move .CellLeft + .Left, .CellTop+
.Top, .CellWidth, .CellHeight
txtDataEntry.Visible = True
DoEvents
txtDataEntry.SetFocus
End With
End If
End Sub
Private Sub MSHFlexGrid1_GotFocus()
Call SaveEdits
End Sub
Private Sub MSHFlexGrid1_KeyPress(KeyAscii As Integer)
If MSHFlexGrid1.Col = 3 Then
Select Case KeyAscii
Case 48 To 57
txtDataEntry.Text = Chr$(KeyAscii)
txtDataEntry.SelStart = 1
End Select
With MSHFlexGrid1
txtDataEntry.Move .CellLeft + .Left, .CellTop + .Top, .CellWidth, .CellHeight
txtDataEntry.Visible = True
DoEvents
txtDataEntry.SetFocus
End With
End If
End Sub
Private Sub MSHFlexGrid1_LeaveCell()
Call SaveEdits
End Sub
Private Sub txtDataEntry_KeyPress(KeyAscii As Integer)
Select Case KeyAscii
Case 48 To 57
Case Else
KeyAscii = 0
End Select
End Sub
Private Sub SaveEdits()
If Not (txtDataEntry.Visible) Then Exit Sub
MSHFlexGrid1.TextMatrix(MSHFlexGrid1.Row, MSHFlexGrid1.Col) = txtDataEntry.Text
txtDataEntry.Visible = False
End Sub