Flex Grid
Flex Grid
htm
Full code listing
Option Explicit
Private Sub SetGridProperties()
With grdInfo
.Cols = 4
.Rows = 1
.FocusRect = flexFocusHeavy
.SelectionMode = flexSelectionFree
.ColWidth(0) = 200
.ColWidth(1) = 1350
.ColWidth(2) = 1400
.ColWidth(3) = 1000
.Row = 0
.Col = 1
.Text = "First Name"
.Col = 2
.Text = "Last Name"
.Col = 3
.Text = "Middle Initial"
End With
End Sub
Private Sub FillData()
'add data
With grdInfo
.AddItem "1" & vbTab & "Michael" & vbTab & "Foster" & vbTab & "M"
.AddItem "2" & vbTab & "Angela" & vbTab & "Johnson" & vbTab & "K"
.AddItem "3" & vbTab & "Alex" & vbTab & "Smith" & vbTab & "H"
End With
'move to first cell
With grdInfo
.Col = 1
.Row = 1
End With
End Sub
Private Sub Form_Load()
Call SetGridProperties
Call FillData
End Sub
Private Sub grdInfo_KeyPress(KeyAscii As Integer)
Select Case KeyAscii
Case 65 To 90, 97 To 122, 48 To 57 'valid characters(letters & numbers
only)
grdInfo.Text = grdInfo.Text & Chr(KeyAscii)
Case 8 'backspace
If Len(grdInfo.Text) > 0 Then
grdInfo.Text = Left(grdInfo.Text, (Len(grdInfo.Text) - 1))
End If
Case Else 'invalid characters
KeyAscii = 0
Beep
End Select
End Sub