Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Text Box with MSHFlexGrid

Status
Not open for further replies.

AMHCLH

Programmer
Nov 26, 2002
23
0
0
US
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
 

If you move from the txtDataEntry textbox to a button or some other control, the SaveEdit routine (called in your MSHFlexgrid_GotFocus event) will not be executed until the grid get the focus again( i.e another cell is clicked). To update right away, use the textbox's lostfocus event. On the click of the flexgrid, save the clicked cell and row in two variables. When the textbox loses focus, set the flexgrid Row, column text. This will help if the flexgrid is clicked on from the text box (Row & Col will not be the edited row & col), and be updated if any other control is selected.

'module level variables
Dim mintEditRow as Integer
Dim mintEditCol as Integer


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
mintEditRow = .Row
mintEditCol = .Col
DoEvents
txtDataEntry.SetFocus
End With
End If
End Sub

Sub txtDataEntry_LostFocus()
MSHFlexGrid1.TextMatrix(mintEditRow, mintEditCol) = txtDataEntry.Text
End Sub


Mark

"You guys pair up in groups of three, then line up in a circle."
- Bill Peterson, a Florida State football coach
 
Mark,

Tried that code change and still get the same results. The number doesn't appear until I leave the cell.
 
Is the flexgrid in a frame or similar container? If so, the txtDataEntry textbox will have to be in the same container--not simply located on the form. If that's the case, the textbox will probably appear behind the container and not be visible, yet accept and process the keystrokes...



Mark

"You guys pair up in groups of three, then line up in a circle."
- Bill Peterson, a Florida State football coach
 
No, there is no container or frame. The items are just on a form. The puzzling thing is that it worked with the MSFLEXGRID, but now it doesn't with the MSHFLEXGRID.
 


If you've removed the MSFlexgrid and put in its place an MSHFlexgrid, the order in the layer may be different. Anything contained in a layer closer to the front covers anything contained in the layer(s) behind it.

Try putting txtDataEntry.ZOrder(0) in the Form_Load event to force the textbox to the front of all the other controls on the same layer (Or click on the textbox and hit Ctrl+J).











Mark

"You guys pair up in groups of three, then line up in a circle."
- Bill Peterson, a Florida State football coach
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top