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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

ATT: VB gurus. Msflexgrid and entering data

Status
Not open for further replies.

zann

Programmer
Nov 7, 2002
7
0
0
ZA
Hi all

i would like to know if anyone has sample code to enter info into an mslfexxgrid using a textbox. the textbox is placed over the cell in the msflexgrid which is highlighted when clicked on. I would appreciate some help.

if there is of course another component that one could use could they please point it out to me.

thanx in advance
 
Try this.....

Sub GridEdit(KeyAscii As Integer)
'use correct font

Text1.FontName = MSFlexGrid1.FontName
Text1.FontSize = MSFlexGrid1.FontSize
Select Case KeyAscii
Case 0 To Asc(" ")
Text1 = MSFlexGrid1
Text1.SelStart = 1000
Case Else
Text1 = Chr(KeyAscii)
Text1.SelStart = 1
End Select

'position the edit box
Text1.Left = MSFlexGrid1.CellLeft + MSFlexGrid1.Left
Text1.Top = MSFlexGrid1.CellTop + MSFlexGrid1.Top
Text1.Width = MSFlexGrid1.CellWidth
Text1.Height = MSFlexGrid1.CellHeight
Text1.Visible = True
Text1.SetFocus
End Sub

Private Sub msflexgrid1_LeaveCell()
If Text1.Visible Then
MSFlexGrid1 = Text1
Text1.Visible = False
End If
End Sub

Private Sub msflexgrid1_GotFocus()
If Text1.Visible Then
MSFlexGrid1 = Text1
Text1.Visible = False
End If
End Sub
Private Sub Text1_KeyDown(KeyCode As Integer, Shift As Integer)
Select Case KeyCode
Case vbKeyEscape
Text1.Visible = False
MSFlexGrid1.SetFocus
Case vbKeyReturn
MSFlexGrid1.SetFocus
Case vbKeyDown
MSFlexGrid1.SetFocus
DoEvents
If MSFlexGrid1.Row < MSFlexGrid1.Rows - 1 Then
MSFlexGrid1.Row = MSFlexGrid1.Row + 1
End If
Case vbKeyUp
MSFlexGrid1.SetFocus
DoEvents
If MSFlexGrid1.Row > MSFlexGrid1.FixedRows Then
MSFlexGrid1.Row = MSFlexGrid1.Row - 1
End If
End Select
End Sub
Private Sub Text1_KeyPress(KeyAscii As Integer)
'noise suppression
If KeyAscii = vbKeyReturn Then KeyAscii = 0
End Sub

Private Sub msflexgrid1_DblClick()
GridEdit Asc(&quot; &quot;)
End Sub
Private Sub msflexgrid1_KeyPress(KeyAscii As Integer)
GridEdit KeyAscii
End Sub

 
If you are interested I can email you a small test project that shows how I use a floating text box and floating combo box with the msflexgrid.

Let me know via email or post your email address. Thanks and Good Luck!

zemp
 
Try this (or something like it) -

Private Sub MSFlexGrid1_KeyPress(KeyAscii As Integer)

With MSFlexGrid1
Select Case KeyAscii
Case 8
On Error Resume Next
.Text = Left$(.Text, Len(.Text) - 1)
Case Else
.Text = .Text & Chr$(KeyAscii)
End Select
End With

End Sub

Now, you don't need a text box. Just click on the cel you want and start entering.

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top