本来通过ERP中基础分类档案的每级编码规则控制来展现MSFlexGrid控件的使用技巧,大家只要向控件添加一个MSFlexGrid及Combo控件就好了,源码如下:
Option Explicit
Private Sub Combo1_Click()
MSFlexGrid1.text = Combo1.text
End Sub
Private Sub Combo1_KeyPress(KeyAscii As Integer)
If KeyAscii = vbKeyEscape Then
Combo1.Visible = False
MSFlexGrid1.SetFocus
Exit Sub
End If
If KeyAscii = vbKeyReturn Then
MSFlexGrid1.text = Combo1.text
Combo1.Visible = False
MSFlexGrid1.SetFocus
End If
End Sub
Private Sub Combo1_LostFocus()
Combo1.Visible = False
MSFlexGrid1.SetFocus
Exit Sub
End Sub
Private Sub Form_Load()
Dim i As Integer
Dim width, text, Archives
width = Array("400", "2100", "800", "800", "800", "800", "800", "800", "800", "800", "800")
text = Array("序号", "档案名称", "第1级", "第2级", "第3级", "第4级", "第5级", "第6级", "第7级", "第8级", "第9级")
Archives = Array("null", "科目", "项目分类", "固定资产分类", "部门分类", "员工分类", "供应商分类", "客户分类", "销售商分类", "地区分类", "出入库类别", "存货分类", "预留12", "预留13", "预留14", "预留15", "预留16", "预留17", "预留18", "预留19", "预留20")
With MSFlexGrid1
.Rows = 21
.Cols = 11
.FixedCols = 2
.FixedRows = 1
End With
For i = 1 To 9
Combo1.AddItem i
Next i
For i = 0 To 10
MSFlexGrid1.ColWidth(i) = width(i)
MSFlexGrid1.TextMatrix(0, i) = text(i)
Next i
For i = 1 To 20
With MSFlexGrid1
.TextMatrix(i, 0) = i
.TextMatrix(i, 1) = Archives(i)
.RowHeight(i) = 300
End With
Next i
End Sub
Private Sub MSFlexGrid1_Click()
Dim c As Integer, r As Integer
With MSFlexGrid1
c = .col
r = .row
If c > 1 And r > 0 Then
Combo1.Left = .Left + .ColPos(c) + 50
Combo1.Top = .Top + .RowPos(r) + 50
Combo1.width = .ColWidth(c)
Combo1.text = .text
Combo1.Visible = True
Combo1.SetFocus
End If
End With
End Sub
Private Sub MSFlexGrid1_KeyPress(KeyAscii As Integer)
If KeyAscii = vbKeyReturn Then
Call MSFlexGrid1_Click
End If
End Sub
关键词:MSFlexGrid运用技巧一例