怎样在MSFlexGrid上动态加其他控件?
如题,谢谢!
[解决办法]
那combol和textbox做个示例,其实很简单,只是定位的问题,其他控件也可以按这个办法加
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 ", "800 ", "800 ", "800 ", "800 ", "800 ", "800 ", "800 ", "800 ", "800 ")
text = Array( "序号 ", "第1级 ", "第2级 ", "第3级 ", "第4级 ", "第5级 ", "第6级 ", "第7级 ", "第8级 ", "第9级 ")
With MSFlexGrid1
.Rows = 21
.Cols = 10
.FixedCols = 1
.FixedRows = 1
End With
For i = 1 To 9
Combo1.AddItem i
Next i
For i = 0 To 9
MSFlexGrid1.ColWidth(i) = width(i)
MSFlexGrid1.TextMatrix(0, i) = text(i)
Next i
For i = 1 To 20
With MSFlexGrid1
.TextMatrix(i, 0) = i
.RowHeight(i) = 300
End With
Next i
End Sub
Private Sub MSFlexGrid1_Click()
Dim c As Integer, r As Integer
Dim n As Integer, m As Integer
m = Me.MSFlexGrid1.MouseCol
n = Me.MSFlexGrid1.MouseRow
'判断是否点在固定列上
If m > 0 Or n > 0 Then
Text1.Visible = False
Combo1.Visible = False
End If
With MSFlexGrid1
c = .Col
r = .Row
If c = 1 And r > 0 And m > 0 And n > 0 Then
Text1.Left = .Left + .ColPos(c) + 50
Text1.Top = .Top + .RowPos(r) + 50
Text1.width = .ColWidth(c)
Text1.Height = .RowHeight(c)
Text1.text = .text
Combo1.Visible = False
Text1.Visible = True
Text1.SetFocus
End If
If c > 1 And r > 0 And m > 0 And n > 0 Then
Combo1.Left = .Left + .ColPos(c) + 50
Combo1.Top = .Top + .RowPos(r) + 50
Combo1.width = .ColWidth(c)
Combo1.text = .text
Text1.Visible = False
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
Private Sub Text1_Change()
MSFlexGrid1.text = Text1.text
End Sub