VERSION 5.00
Object = "{5E9E78A0-531B-11CF-91F6-C2863C385E30}#1.0#0"; "MSFLXGRD.OCX"
Begin VB.Form FlexGridForm
Caption = "Form1"
ClientHeight = 2400
ClientLeft = 60
ClientTop = 345
ClientWidth = 6840
LinkTopic = "Form1"
ScaleHeight = 2400
ScaleWidth = 6840
StartUpPosition = 3
'Windows Default
Begin VB.TextBox Text1
Height = 285
Left = 4560
TabIndex = 2
Text = "Text1"
Top = 600
Width = 1215
End
Begin VB.ComboBox Combo1
Height = 315
Left = 4560
Sorted = -1
'True
Style = 2
'Dropdown List
TabIndex = 1
Top = 120
Width = 1215
End
Begin MSFlexGridLib.MSFlexGrid MSFlexGrid1
Height = 1935
Left = 120
TabIndex = 0
Top = 360
Width = 4335
_ExtentX = 7646
_ExtentY = 3413
_Version = 393216
AllowUserResizing= 3
End
End
Attribute VB_Name = "FlexGridForm"
Attribute VB_GlobalNameSpace =
False
Attribute VB_Creatable =
False
Attribute VB_PredeclaredId =
True
Attribute VB_Exposed =
False
Option Explicit
Private Sub EndEdit()
If Combo1.Visible
Then
MSFlexGrid1.Text = Combo1.Text
Combo1.Visible =
False
ElseIf Text1.Visible
Then
MSFlexGrid1.Text = Text1.Text
Text1.Visible =
False
End If
End Sub
Private Sub StartEdit()
GridEditText Asc(" "
End Sub
' Make the change.
Private Sub Combo1_Click()
MSFlexGrid1.SetFocus
End Sub
Private Sub Form_Load()
Dim r
As Long
Dim c
As Long
Dim max_len
As Single
Dim new_len
As Single
' Use no border.
Text1.BorderStyle = vbBSNone
' Make the grid's cell height match
' that of the ComboBox.
MSFlexGrid1.RowHeightMin = Combo1.Height
' Match the grid's font.
Text1.FontName = MSFlexGrid1.FontName
Text1.FontSize = MSFlexGrid1.FontSize
Text1.Visible =
False
Combo1.FontName = MSFlexGrid1.FontName
Combo1.FontSize = MSFlexGrid1.FontSize
Combo1.Visible =
False
' Create some data.
MSFlexGrid1.FixedCols = 0
MSFlexGrid1.Cols = 2
MSFlexGrid1.FixedRows = 1
MSFlexGrid1.Rows = 150000
MSFlexGrid1.HighLight = flexHighlightNever
Dim i
As Long
For i = 1
To 149999
MSFlexGrid1.TextMatrix(i, 0) = "
Name" & Rnd
MSFlexGrid1.TextMatrix(i, 1) = "Value" & Rnd
Next
' Size the columns.
Font.
Name = MSFlexGrid1.Font.
Name
Font.Size = MSFlexGrid1.Font.Size
For c = 0
To MSFlexGrid1.Cols - 1
max_len = 0
For r = 0
To MSFlexGrid1.Rows - 1
new_len = TextWidth(MSFlexGrid1.TextMatrix(r, c))
If max_len < new_len
Then max_len = new_len
Next r
MSFlexGrid1.ColWidth(c) = max_len + 240
MSFlexGrid1.ColAlignment(c) = flexAlignLeftCenter
Next c
MSFlexGrid1.AllowUserResizing = flexResizeBoth
End Sub
Private Sub GridEditText(
ByVal KeyAscii As
Integer)
' Position the TextBox over the cell.
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
Select Case KeyAscii
Case 0
To Asc(" "
Text1.Text = MSFlexGrid1.Text
Text1.SelStart =
Len(Text1.Text)
Case Else
Text1.Text = Chr$(KeyAscii)
Text1.SelStart = 1
End Select
End Sub
Private Sub Form_Resize()
MSFlexGrid1.Move 0, 0, ScaleWidth, ScaleHeight
End Sub
Private Sub Text1_KeyDown(KeyCode
As Integer, Shift
As Integer)
Select Case KeyCode
Case vbKeyEscape
' Leave the text unchanged.
Text1.Visible =
False
MSFlexGrid1.SetFocus
Case vbKeyReturn
' Finish editing.
MSFlexGrid1.SetFocus
Case vbKeyDown
' Move down 1 row.
MSFlexGrid1.SetFocus
DoEvents
If MSFlexGrid1.Row < MSFlexGrid1.Rows - 1
Then
MSFlexGrid1.Row = MSFlexGrid1.Row + 1
End If
Case vbKeyUp
' Move up 1 row.
MSFlexGrid1.SetFocus
DoEvents
If MSFlexGrid1.Row > MSFlexGrid1.FixedRows
Then
MSFlexGrid1.Row = MSFlexGrid1.Row - 1
End If
End Select
End Sub
' Do not beep on Return or Escape.
Private Sub Text1_KeyPress(KeyAscii As
Integer)
If (KeyAscii = vbKeyReturn)
Or _
 
KeyAscii = vbKeyEscape) _
Then KeyAscii = 0
End Sub
Private Sub MSFlexGrid1_DblClick()
StartEdit
End Sub
Private Sub MSFlexGrid1_KeyPress(KeyAscii As
Integer)
If MSFlexGrid1.Col <> 2
And _
MSFlexGrid1.Col <> 3 _
Then
GridEditText KeyAscii
End If
End Sub
Private Sub MSFlexGrid1_LeaveCell()
EndEdit
End Sub
Private Sub MSFlexGrid1_GotFocus()
EndEdit
End Sub