添加的控件有MSFlexGrid、下拉组合框
MSFlexGrid的容器建小一点以便有上下的滚动条和水平的左右的滚动条
暂时发现的BUG是1、回车按到最右边一行时,当前显示MSFlexGrid的列不能显示到最右边
2、先把水平的滚动条拉到最右边,然后点击下面的行(大于一行空行的行)
3、还有的是单价和数量的只能输数字和小数点
代码如下:
Dim enr As Boolean
Private Sub Form_Activate()
Dim i As Integer
MSFlexGrid1.Rows = 16
MSFlexGrid1.Cols = 8 MSFlexGrid1.ColWidth(0) = 1 * 20 * 0
MSFlexGrid1.RowHeight(0) = 8 * 18 * 2
For i = 1 To 7
MSFlexGrid1.ColWidth(i) = 10 * 12 * 12
Next i
For i = 1 To 15
MSFlexGrid1.RowHeight(i) = 8 * 18 * 2
Next i
MSFlexGrid1.FixedRows = 1
MSFlexGrid1.FixedCols = 1
MSFlexGrid1.TextMatrix(0, 0) = "编号"
MSFlexGrid1.TextMatrix(0, 1) = "商品代码"
MSFlexGrid1.TextMatrix(0, 2) = "商品名"
MSFlexGrid1.TextMatrix(0, 3) = "型号规格"
MSFlexGrid1.TextMatrix(0, 4) = "数量"
MSFlexGrid1.TextMatrix(0, 5) = "单位"
MSFlexGrid1.TextMatrix(0, 6) = "单价"
MSFlexGrid1.TextMatrix(0, 7) = "金额"
MSFlexGrid1.Text = Combo1.Text
Combo1.Visible = False
End SubPrivate Sub MSFlexGrid1_Click()
followtable
If MSFlexGrid1.TextMatrix(MSFlexGrid1.Row - 1, 1) = "" And MSFlexGrid1.TextMatrix(MSFlexGrid1.Row - 1, 2) = "" _
And MSFlexGrid1.TextMatrix(MSFlexGrid1.Row - 1, 3) = "" And MSFlexGrid1.TextMatrix(MSFlexGrid1.Row - 1, 4) = "" _
And MSFlexGrid1.TextMatrix(MSFlexGrid1.Row - 1, 5) = "" And MSFlexGrid1.TextMatrix(MSFlexGrid1.Row - 1, 6) = "" _
And MSFlexGrid1.TextMatrix(MSFlexGrid1.Row - 1, 7) = "" Then
For i = 1 To MSFlexGrid1.Row - 1
If MSFlexGrid1.TextMatrix(i, 1) = "" And MSFlexGrid1.TextMatrix(i, 2) = "" _
And MSFlexGrid1.TextMatrix(i, 3) = "" And MSFlexGrid1.TextMatrix(i, 4) = "" _
And MSFlexGrid1.TextMatrix(i, 5) = "" And MSFlexGrid1.TextMatrix(i, 6) = "" _
And MSFlexGrid1.TextMatrix(i, 7) = "" Then Exit For
Next i
MSFlexGrid1.Row = i
MSFlexGrid1.TopRow = i
MSFlexGrid1.Col = 1
End If
followtable
End Sub
Private Sub MSFlexGrid1_LeaveCell()
If enr = False Then
MSFlexGrid1.Text = Combo1.Text
End If
End SubPrivate Sub MSFlexGrid1_Scroll()
Combo1.Visible = False
End SubPrivate Sub COMBO1_KeyPress(KeyAscii As Integer)
On Error Resume Next
If KeyAscii = vbKeyReturn Then
MSFlexGrid1.Text = Combo1.Text
If MSFlexGrid1.Col < 7 Then
MSFlexGrid1.Col = MSFlexGrid1.Col + 1
Else
enr = True
MSFlexGrid1.Col = 1
MSFlexGrid1.Row = MSFlexGrid1.Row + 1
If MSFlexGrid1.TextMatrix(MSFlexGrid1.Row - 1, 1) = "" And MSFlexGrid1.TextMatrix(MSFlexGrid1.Row - 1, 2) = "" _
And MSFlexGrid1.TextMatrix(MSFlexGrid1.Row - 1, 3) = "" And MSFlexGrid1.TextMatrix(MSFlexGrid1.Row - 1, 4) = "" _
And MSFlexGrid1.TextMatrix(MSFlexGrid1.Row - 1, 5) = "" And MSFlexGrid1.TextMatrix(MSFlexGrid1.Row - 1, 6) = "" _
And MSFlexGrid1.TextMatrix(MSFlexGrid1.Row - 1, 7) = "" Then
MSFlexGrid1.Row = MSFlexGrid1.Row - 1
MSFlexGrid1.Col = MSFlexGrid1.Col - 2
End If
enr = False
If Err = 30009 Then
MSFlexGrid1.AddItem (MSFlexGrid1.Rows)
enr = True
MSFlexGrid1.Col = 1
MSFlexGrid1.Row = MSFlexGrid1.Row + 1
MSFlexGrid1.ColWidth(Rows - 1) = 10 * 12 * 12
MSFlexGrid1.RowHeight(Rows - 1) = 8 * 18 * 2
MSFlexGrid1.ColWidth(0) = 1 * 20 * 0
MSFlexGrid1.RowHeight(0) = 8 * 18 * 2
MSFlexGrid1.TopRow = MSFlexGrid1.Rows - 1
If MSFlexGrid1.TextMatrix(MSFlexGrid1.Row - 1, 1) = "" And MSFlexGrid1.TextMatrix(MSFlexGrid1.Row - 1, 2) = "" _
And MSFlexGrid1.TextMatrix(MSFlexGrid1.Row - 1, 3) = "" And MSFlexGrid1.TextMatrix(MSFlexGrid1.Row - 1, 4) = "" _
And MSFlexGrid1.TextMatrix(MSFlexGrid1.Row - 1, 5) = "" And MSFlexGrid1.TextMatrix(MSFlexGrid1.Row - 1, 6) = "" _
And MSFlexGrid1.TextMatrix(MSFlexGrid1.Row - 1, 7) = "" Then
MSFlexGrid1.Row = MSFlexGrid1.Row - 1
MSFlexGrid1.Col = MSFlexGrid1.Col - 2
End If
enr = False
End If
End If
followtable
End If
End SubPrivate Sub COMBO1_Change()
Dim A As Single
If MSFlexGrid1.Col = 4 Then
MSFlexGrid1.Text = Combo1.Text
'求金额
A = Val(MSFlexGrid1.TextMatrix(MSFlexGrid1.Row, 4)) * Val(MSFlexGrid1.TextMatrix(MSFlexGrid1.Row, 6))
If A = 0 Then MSFlexGrid1.TextMatrix(MSFlexGrid1.Row, 7) = "": Exit Sub
MSFlexGrid1.TextMatrix(MSFlexGrid1.Row, 7) = Format(A, "0.00")
End If
If MSFlexGrid1.Col = 6 Then
MSFlexGrid1.Text = Combo1.Text
'求金额
A = Val(MSFlexGrid1.TextMatrix(MSFlexGrid1.Row, 4)) * Val(MSFlexGrid1.TextMatrix(MSFlexGrid1.Row, 6))
If A = 0 Then MSFlexGrid1.TextMatrix(MSFlexGrid1.Row, 7) = "": Exit Sub
MSFlexGrid1.TextMatrix(MSFlexGrid1.Row, 7) = Format(A, "0.00")
End If
End Sub
Sub followtable()
Combo1.Left = MSFlexGrid1.Left + MSFlexGrid1.ColPos(MSFlexGrid1.Col)
Combo1.Top = MSFlexGrid1.Top + MSFlexGrid1.RowPos(MSFlexGrid1.Row)
Combo1.Width = MSFlexGrid1.ColWidth(MSFlexGrid1.Col)
Combo1 = MSFlexGrid1.Text
Combo1.Visible = True
Combo1.SetFocus
End Sub
MSFlexGrid的容器建小一点以便有上下的滚动条和水平的左右的滚动条
暂时发现的BUG是1、回车按到最右边一行时,当前显示MSFlexGrid的列不能显示到最右边
2、先把水平的滚动条拉到最右边,然后点击下面的行(大于一行空行的行)
3、还有的是单价和数量的只能输数字和小数点
代码如下:
Dim enr As Boolean
Private Sub Form_Activate()
Dim i As Integer
MSFlexGrid1.Rows = 16
MSFlexGrid1.Cols = 8 MSFlexGrid1.ColWidth(0) = 1 * 20 * 0
MSFlexGrid1.RowHeight(0) = 8 * 18 * 2
For i = 1 To 7
MSFlexGrid1.ColWidth(i) = 10 * 12 * 12
Next i
For i = 1 To 15
MSFlexGrid1.RowHeight(i) = 8 * 18 * 2
Next i
MSFlexGrid1.FixedRows = 1
MSFlexGrid1.FixedCols = 1
MSFlexGrid1.TextMatrix(0, 0) = "编号"
MSFlexGrid1.TextMatrix(0, 1) = "商品代码"
MSFlexGrid1.TextMatrix(0, 2) = "商品名"
MSFlexGrid1.TextMatrix(0, 3) = "型号规格"
MSFlexGrid1.TextMatrix(0, 4) = "数量"
MSFlexGrid1.TextMatrix(0, 5) = "单位"
MSFlexGrid1.TextMatrix(0, 6) = "单价"
MSFlexGrid1.TextMatrix(0, 7) = "金额"
MSFlexGrid1.Text = Combo1.Text
Combo1.Visible = False
End SubPrivate Sub MSFlexGrid1_Click()
followtable
If MSFlexGrid1.TextMatrix(MSFlexGrid1.Row - 1, 1) = "" And MSFlexGrid1.TextMatrix(MSFlexGrid1.Row - 1, 2) = "" _
And MSFlexGrid1.TextMatrix(MSFlexGrid1.Row - 1, 3) = "" And MSFlexGrid1.TextMatrix(MSFlexGrid1.Row - 1, 4) = "" _
And MSFlexGrid1.TextMatrix(MSFlexGrid1.Row - 1, 5) = "" And MSFlexGrid1.TextMatrix(MSFlexGrid1.Row - 1, 6) = "" _
And MSFlexGrid1.TextMatrix(MSFlexGrid1.Row - 1, 7) = "" Then
For i = 1 To MSFlexGrid1.Row - 1
If MSFlexGrid1.TextMatrix(i, 1) = "" And MSFlexGrid1.TextMatrix(i, 2) = "" _
And MSFlexGrid1.TextMatrix(i, 3) = "" And MSFlexGrid1.TextMatrix(i, 4) = "" _
And MSFlexGrid1.TextMatrix(i, 5) = "" And MSFlexGrid1.TextMatrix(i, 6) = "" _
And MSFlexGrid1.TextMatrix(i, 7) = "" Then Exit For
Next i
MSFlexGrid1.Row = i
MSFlexGrid1.TopRow = i
MSFlexGrid1.Col = 1
End If
followtable
End Sub
Private Sub MSFlexGrid1_LeaveCell()
If enr = False Then
MSFlexGrid1.Text = Combo1.Text
End If
End SubPrivate Sub MSFlexGrid1_Scroll()
Combo1.Visible = False
End SubPrivate Sub COMBO1_KeyPress(KeyAscii As Integer)
On Error Resume Next
If KeyAscii = vbKeyReturn Then
MSFlexGrid1.Text = Combo1.Text
If MSFlexGrid1.Col < 7 Then
MSFlexGrid1.Col = MSFlexGrid1.Col + 1
Else
enr = True
MSFlexGrid1.Col = 1
MSFlexGrid1.Row = MSFlexGrid1.Row + 1
If MSFlexGrid1.TextMatrix(MSFlexGrid1.Row - 1, 1) = "" And MSFlexGrid1.TextMatrix(MSFlexGrid1.Row - 1, 2) = "" _
And MSFlexGrid1.TextMatrix(MSFlexGrid1.Row - 1, 3) = "" And MSFlexGrid1.TextMatrix(MSFlexGrid1.Row - 1, 4) = "" _
And MSFlexGrid1.TextMatrix(MSFlexGrid1.Row - 1, 5) = "" And MSFlexGrid1.TextMatrix(MSFlexGrid1.Row - 1, 6) = "" _
And MSFlexGrid1.TextMatrix(MSFlexGrid1.Row - 1, 7) = "" Then
MSFlexGrid1.Row = MSFlexGrid1.Row - 1
MSFlexGrid1.Col = MSFlexGrid1.Col - 2
End If
enr = False
If Err = 30009 Then
MSFlexGrid1.AddItem (MSFlexGrid1.Rows)
enr = True
MSFlexGrid1.Col = 1
MSFlexGrid1.Row = MSFlexGrid1.Row + 1
MSFlexGrid1.ColWidth(Rows - 1) = 10 * 12 * 12
MSFlexGrid1.RowHeight(Rows - 1) = 8 * 18 * 2
MSFlexGrid1.ColWidth(0) = 1 * 20 * 0
MSFlexGrid1.RowHeight(0) = 8 * 18 * 2
MSFlexGrid1.TopRow = MSFlexGrid1.Rows - 1
If MSFlexGrid1.TextMatrix(MSFlexGrid1.Row - 1, 1) = "" And MSFlexGrid1.TextMatrix(MSFlexGrid1.Row - 1, 2) = "" _
And MSFlexGrid1.TextMatrix(MSFlexGrid1.Row - 1, 3) = "" And MSFlexGrid1.TextMatrix(MSFlexGrid1.Row - 1, 4) = "" _
And MSFlexGrid1.TextMatrix(MSFlexGrid1.Row - 1, 5) = "" And MSFlexGrid1.TextMatrix(MSFlexGrid1.Row - 1, 6) = "" _
And MSFlexGrid1.TextMatrix(MSFlexGrid1.Row - 1, 7) = "" Then
MSFlexGrid1.Row = MSFlexGrid1.Row - 1
MSFlexGrid1.Col = MSFlexGrid1.Col - 2
End If
enr = False
End If
End If
followtable
End If
End SubPrivate Sub COMBO1_Change()
Dim A As Single
If MSFlexGrid1.Col = 4 Then
MSFlexGrid1.Text = Combo1.Text
'求金额
A = Val(MSFlexGrid1.TextMatrix(MSFlexGrid1.Row, 4)) * Val(MSFlexGrid1.TextMatrix(MSFlexGrid1.Row, 6))
If A = 0 Then MSFlexGrid1.TextMatrix(MSFlexGrid1.Row, 7) = "": Exit Sub
MSFlexGrid1.TextMatrix(MSFlexGrid1.Row, 7) = Format(A, "0.00")
End If
If MSFlexGrid1.Col = 6 Then
MSFlexGrid1.Text = Combo1.Text
'求金额
A = Val(MSFlexGrid1.TextMatrix(MSFlexGrid1.Row, 4)) * Val(MSFlexGrid1.TextMatrix(MSFlexGrid1.Row, 6))
If A = 0 Then MSFlexGrid1.TextMatrix(MSFlexGrid1.Row, 7) = "": Exit Sub
MSFlexGrid1.TextMatrix(MSFlexGrid1.Row, 7) = Format(A, "0.00")
End If
End Sub
Sub followtable()
Combo1.Left = MSFlexGrid1.Left + MSFlexGrid1.ColPos(MSFlexGrid1.Col)
Combo1.Top = MSFlexGrid1.Top + MSFlexGrid1.RowPos(MSFlexGrid1.Row)
Combo1.Width = MSFlexGrid1.ColWidth(MSFlexGrid1.Col)
Combo1 = MSFlexGrid1.Text
Combo1.Visible = True
Combo1.SetFocus
End Sub
MSFlexGrid1.LeftCol = 2