Click to See Complete Forum and Search --> : Table Control


jerry.gadd
March 30th, 2001, 09:27 AM
Hi, I am quite new to VB.
But I need a control that acts like a table.
Where the user can click in any field in the table and enter a value.
Each column in my table must ave a header.

Can anybody suggest what control I should use?


Regards,
Jerry Gadd

Ratings are my only reason for living, so GIVE ME HIGH ONES, or have my death on your consience.

shree
March 30th, 2001, 09:41 AM
The MS FlexGrid Control.

shree
March 30th, 2001, 09:54 AM
The MSFlexGrid doesn't inherently allow you to edit data in a cell. Here is the code that illustrates a workaround, using a textbox.

Place a textbox on a form and set the following properties

Appearance = 0 'Flat
BorderStyle = 0 'None
Height = 375
Left = 1560
TabIndex = 1
Text
Top = 240
Width = 1455

And a MSFlexGrid control with the following properties

Height = 2895
Left = 600
TabIndex = 0
Top = 720
Width = 4215
Rows = 5
Cols = 5

Now paste the following code into the form


private Sub MSFlexGrid1_DblClick()
GridEdit Asc(" ")
End Sub

private Sub MSFlexGrid1_KeyPress(KeyAscii as Integer)
GridEdit KeyAscii
End Sub
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

jerry.gadd
March 30th, 2001, 10:30 AM
Just what I was looking for
Thank you.!!!!!!!!!!!!!!!!!!!!!

Regards,
Jerry Gadd

Ratings are my only reason for living, so GIVE ME HIGH ONES, or have my death on your consience.