如果执行mshflexgrid1.clear,则连表头的内容也没了,再填充数据时还要先填充表头。如何能做到清除表格内容,但是保留表头呢?
15 个解决方案
#1
mark
#2
有两种方法,
1.
msh.rows=msh.fixedrows
2
for i = msh.fixedrows to msh.rows-msh.fixedrows
for j=msh.fixedcols to msh.cols-1
msh.textMatrix(i,j)=""
next j
next i
1.
msh.rows=msh.fixedrows
2
for i = msh.fixedrows to msh.rows-msh.fixedrows
for j=msh.fixedcols to msh.cols-1
msh.textMatrix(i,j)=""
next j
next i
#3
学习一下
#4
1.
msh.rows=msh.fixedrows
----------------
这种方法不知与clear有何区别?是不是只是感觉上行小了,实际内存中还有呀?
2
for i = msh.fixedrows to msh.rows-msh.fixedrows
for j=msh.fixedcols to msh.cols-1
msh.textMatrix(i,j)=""
next j
next i
-----------------
这种方法是不是比clear的效率低很多?因为这要进行双重循环,比第一种要消耗很多,而且要一个格子一个格子的清除。
msh.rows=msh.fixedrows
----------------
这种方法不知与clear有何区别?是不是只是感觉上行小了,实际内存中还有呀?
2
for i = msh.fixedrows to msh.rows-msh.fixedrows
for j=msh.fixedcols to msh.cols-1
msh.textMatrix(i,j)=""
next j
next i
-----------------
这种方法是不是比clear的效率低很多?因为这要进行双重循环,比第一种要消耗很多,而且要一个格子一个格子的清除。
#5
我晕.那有那么复杂啊,先把 Rows=0,再恢复到原来的行数,如果你不需要回复就把后面那句不要嘛,还去清除.....不嫌麻烦啊..
Private Sub Command1_Click()
Dim i As Integer
i = Me.MSFlexGrid1.Rows
Me.MSFlexGrid1.Rows = 1
Me.MSFlexGrid1.Rows = i
End Sub
Private Sub Command1_Click()
Dim i As Integer
i = Me.MSFlexGrid1.Rows
Me.MSFlexGrid1.Rows = 1
Me.MSFlexGrid1.Rows = i
End Sub
#6
效率最高应该是
i=msflexgrid.rows
msflexgrid.rows=msflexgrid.fixedrows
msflexgrid.rows=i
i=msflexgrid.rows
msflexgrid.rows=msflexgrid.fixedrows
msflexgrid.rows=i
#7
先用clear清除
再把表头写进去
再把表头写进去
#8
你的表头有多少行,你就留多少行就行了,如表头有二行,那么就用mshflexgrid.rows=2来清除,下次填充时从mshflexgrid.row=2开始,而且是每次开始填充一行前都用mshflexgrid.rows=mshflexgrid.rows+1来增加一行就行了。
#9
Public Sub gClearGrdEX(Grd As MSHFlexGrid)
Dim indexRow As Integer
Dim indexCol As Integer
With Grd
.Rows = 2
For indexRow = 1 To (.Rows - 1)
For indexCol = 0 To .Cols - 1
.TextMatrix(indexRow, indexCol) = ""
Next
Next
End With
End Sub
Dim indexRow As Integer
Dim indexCol As Integer
With Grd
.Rows = 2
For indexRow = 1 To (.Rows - 1)
For indexCol = 0 To .Cols - 1
.TextMatrix(indexRow, indexCol) = ""
Next
Next
End With
End Sub
#10
同意 ling242a()
#11
写一个定义表头的过程,clear后再调用这个过程,这样再复杂的表头都没问题,比如:
Sub fg_Show() '定义表头,这个表头够复杂吧?呵呵
Dim i As Integer
Dim s As String
With fg
.Cols = 21
.FormatString = s
.TextMatrix(1, 5) = "小时"
.TextMatrix(1, 6) = " 小计"
.TextMatrix(1, 7) = "天数"
.TextMatrix(1, 8) = " 小计"
.TextMatrix(1, 9) = " 合计"
.TextMatrix(1, 12) = "次数"
.TextMatrix(1, 13) = " 小计"
.TextMatrix(1, 14) = "天数"
.TextMatrix(1, 15) = " 小计"
.TextMatrix(1, 16) = " 合计"
.TextMatrix(1, 20) = "id"
'合并表头
' .MergeCells = flexMergeRestrictColumns
.MergeCells = flexMergeFixedOnly
.TextMatrix(0, 0) = "序号"
.TextMatrix(1, 0) = "序号"
.TextMatrix(0, 1) = "姓名"
.TextMatrix(1, 1) = "姓名"
.TextMatrix(0, 2) = " 基本工资"
.TextMatrix(1, 2) = " 基本工资"
.TextMatrix(0, 3) = " 津贴"
.TextMatrix(1, 3) = " 津贴"
.TextMatrix(0, 4) = " 车贴"
.TextMatrix(1, 4) = " 车贴"
.TextMatrix(0, 10) = "+其它 "
.TextMatrix(1, 10) = "+其它 "
.TextMatrix(0, 11) = " 应付工资"
.TextMatrix(1, 11) = " 应付工资"
.TextMatrix(0, 17) = "养老统筹"
.TextMatrix(1, 17) = "养老统筹"
.TextMatrix(0, 18) = "-其它 "
.TextMatrix(1, 18) = "-其它 "
.TextMatrix(0, 19) = " 实发工资"
.TextMatrix(1, 19) = " 实发工资"
.MergeRow(0) = True
.MergeRow(1) = True
For i = 0 To .Cols - 1
Select Case i
Case 0, 1, 2, 3, 4, 10, 11, 17, 18, 19
.MergeCol(i) = True
Case 5, 6, 7, 8, 9
.TextMatrix(0, i) = " 加班工资"
Case 12, 13, 14, 15, 16
.TextMatrix(0, i) = " 考勤违规扣除"
End Select
Next i
'列宽
For i = 0 To .Cols - 1
Select Case i
Case 0
.ColWidth(i) = 400
Case 1, 3, 4, 16, 17, 9
.ColWidth(i) = 780
Case 2, 11, 19
.ColWidth(i) = 930
Case 7, 12, 14
.ColWidth(i) = 470
Case 10, 18
.ColWidth(i) = 1200
Case 20
.ColWidth(i) = 1
Case 13, 15
.ColWidth(i) = 650
Case 5
.ColWidth(i) = 500
Case 6, 8
.ColWidth(i) = 720
End Select
Next i
'表头项居中
For i = 0 To .Cols - 2
Select Case i
Case 0, 1
.ColAlignment(i) = 4
Case 10, 18
.ColAlignment(i) = flexAlignRightCenter
Case Else
.ColAlignment(i) = 9
End Select
Next i
End With
End Sub
Private Sub Form_Load()
call fg_show
End sub
Private Sub Command1_Click()
fg.clear
call fg_show '这样是不是很简单 :)
End sub
Sub fg_Show() '定义表头,这个表头够复杂吧?呵呵
Dim i As Integer
Dim s As String
With fg
.Cols = 21
.FormatString = s
.TextMatrix(1, 5) = "小时"
.TextMatrix(1, 6) = " 小计"
.TextMatrix(1, 7) = "天数"
.TextMatrix(1, 8) = " 小计"
.TextMatrix(1, 9) = " 合计"
.TextMatrix(1, 12) = "次数"
.TextMatrix(1, 13) = " 小计"
.TextMatrix(1, 14) = "天数"
.TextMatrix(1, 15) = " 小计"
.TextMatrix(1, 16) = " 合计"
.TextMatrix(1, 20) = "id"
'合并表头
' .MergeCells = flexMergeRestrictColumns
.MergeCells = flexMergeFixedOnly
.TextMatrix(0, 0) = "序号"
.TextMatrix(1, 0) = "序号"
.TextMatrix(0, 1) = "姓名"
.TextMatrix(1, 1) = "姓名"
.TextMatrix(0, 2) = " 基本工资"
.TextMatrix(1, 2) = " 基本工资"
.TextMatrix(0, 3) = " 津贴"
.TextMatrix(1, 3) = " 津贴"
.TextMatrix(0, 4) = " 车贴"
.TextMatrix(1, 4) = " 车贴"
.TextMatrix(0, 10) = "+其它 "
.TextMatrix(1, 10) = "+其它 "
.TextMatrix(0, 11) = " 应付工资"
.TextMatrix(1, 11) = " 应付工资"
.TextMatrix(0, 17) = "养老统筹"
.TextMatrix(1, 17) = "养老统筹"
.TextMatrix(0, 18) = "-其它 "
.TextMatrix(1, 18) = "-其它 "
.TextMatrix(0, 19) = " 实发工资"
.TextMatrix(1, 19) = " 实发工资"
.MergeRow(0) = True
.MergeRow(1) = True
For i = 0 To .Cols - 1
Select Case i
Case 0, 1, 2, 3, 4, 10, 11, 17, 18, 19
.MergeCol(i) = True
Case 5, 6, 7, 8, 9
.TextMatrix(0, i) = " 加班工资"
Case 12, 13, 14, 15, 16
.TextMatrix(0, i) = " 考勤违规扣除"
End Select
Next i
'列宽
For i = 0 To .Cols - 1
Select Case i
Case 0
.ColWidth(i) = 400
Case 1, 3, 4, 16, 17, 9
.ColWidth(i) = 780
Case 2, 11, 19
.ColWidth(i) = 930
Case 7, 12, 14
.ColWidth(i) = 470
Case 10, 18
.ColWidth(i) = 1200
Case 20
.ColWidth(i) = 1
Case 13, 15
.ColWidth(i) = 650
Case 5
.ColWidth(i) = 500
Case 6, 8
.ColWidth(i) = 720
End Select
Next i
'表头项居中
For i = 0 To .Cols - 2
Select Case i
Case 0, 1
.ColAlignment(i) = 4
Case 10, 18
.ColAlignment(i) = flexAlignRightCenter
Case Else
.ColAlignment(i) = 9
End Select
Next i
End With
End Sub
Private Sub Form_Load()
call fg_show
End sub
Private Sub Command1_Click()
fg.clear
call fg_show '这样是不是很简单 :)
End sub
#12
学习
#13
仔细想来,觉得不执行clear还是不好的,因为这样表面上表格内容已经清了,但实际上单元格内还是有内容的,通过可以恢复内容就可以看出来,所以要想清空内容,就要执行clear,所以执行完clear,再重写一次表头是较好的办法.
个人拙见,不知对否?
个人拙见,不知对否?
#14
up
#15
使用for循环不是可以解决了吗?
with grid
for i=1 to .rows-1
for j=0 to .cols-1
.textmarry(i,j)=""
next
next
end with
with grid
for i=1 to .rows-1
for j=0 to .cols-1
.textmarry(i,j)=""
next
next
end with
#1
mark
#2
有两种方法,
1.
msh.rows=msh.fixedrows
2
for i = msh.fixedrows to msh.rows-msh.fixedrows
for j=msh.fixedcols to msh.cols-1
msh.textMatrix(i,j)=""
next j
next i
1.
msh.rows=msh.fixedrows
2
for i = msh.fixedrows to msh.rows-msh.fixedrows
for j=msh.fixedcols to msh.cols-1
msh.textMatrix(i,j)=""
next j
next i
#3
学习一下
#4
1.
msh.rows=msh.fixedrows
----------------
这种方法不知与clear有何区别?是不是只是感觉上行小了,实际内存中还有呀?
2
for i = msh.fixedrows to msh.rows-msh.fixedrows
for j=msh.fixedcols to msh.cols-1
msh.textMatrix(i,j)=""
next j
next i
-----------------
这种方法是不是比clear的效率低很多?因为这要进行双重循环,比第一种要消耗很多,而且要一个格子一个格子的清除。
msh.rows=msh.fixedrows
----------------
这种方法不知与clear有何区别?是不是只是感觉上行小了,实际内存中还有呀?
2
for i = msh.fixedrows to msh.rows-msh.fixedrows
for j=msh.fixedcols to msh.cols-1
msh.textMatrix(i,j)=""
next j
next i
-----------------
这种方法是不是比clear的效率低很多?因为这要进行双重循环,比第一种要消耗很多,而且要一个格子一个格子的清除。
#5
我晕.那有那么复杂啊,先把 Rows=0,再恢复到原来的行数,如果你不需要回复就把后面那句不要嘛,还去清除.....不嫌麻烦啊..
Private Sub Command1_Click()
Dim i As Integer
i = Me.MSFlexGrid1.Rows
Me.MSFlexGrid1.Rows = 1
Me.MSFlexGrid1.Rows = i
End Sub
Private Sub Command1_Click()
Dim i As Integer
i = Me.MSFlexGrid1.Rows
Me.MSFlexGrid1.Rows = 1
Me.MSFlexGrid1.Rows = i
End Sub
#6
效率最高应该是
i=msflexgrid.rows
msflexgrid.rows=msflexgrid.fixedrows
msflexgrid.rows=i
i=msflexgrid.rows
msflexgrid.rows=msflexgrid.fixedrows
msflexgrid.rows=i
#7
先用clear清除
再把表头写进去
再把表头写进去
#8
你的表头有多少行,你就留多少行就行了,如表头有二行,那么就用mshflexgrid.rows=2来清除,下次填充时从mshflexgrid.row=2开始,而且是每次开始填充一行前都用mshflexgrid.rows=mshflexgrid.rows+1来增加一行就行了。
#9
Public Sub gClearGrdEX(Grd As MSHFlexGrid)
Dim indexRow As Integer
Dim indexCol As Integer
With Grd
.Rows = 2
For indexRow = 1 To (.Rows - 1)
For indexCol = 0 To .Cols - 1
.TextMatrix(indexRow, indexCol) = ""
Next
Next
End With
End Sub
Dim indexRow As Integer
Dim indexCol As Integer
With Grd
.Rows = 2
For indexRow = 1 To (.Rows - 1)
For indexCol = 0 To .Cols - 1
.TextMatrix(indexRow, indexCol) = ""
Next
Next
End With
End Sub
#10
同意 ling242a()
#11
写一个定义表头的过程,clear后再调用这个过程,这样再复杂的表头都没问题,比如:
Sub fg_Show() '定义表头,这个表头够复杂吧?呵呵
Dim i As Integer
Dim s As String
With fg
.Cols = 21
.FormatString = s
.TextMatrix(1, 5) = "小时"
.TextMatrix(1, 6) = " 小计"
.TextMatrix(1, 7) = "天数"
.TextMatrix(1, 8) = " 小计"
.TextMatrix(1, 9) = " 合计"
.TextMatrix(1, 12) = "次数"
.TextMatrix(1, 13) = " 小计"
.TextMatrix(1, 14) = "天数"
.TextMatrix(1, 15) = " 小计"
.TextMatrix(1, 16) = " 合计"
.TextMatrix(1, 20) = "id"
'合并表头
' .MergeCells = flexMergeRestrictColumns
.MergeCells = flexMergeFixedOnly
.TextMatrix(0, 0) = "序号"
.TextMatrix(1, 0) = "序号"
.TextMatrix(0, 1) = "姓名"
.TextMatrix(1, 1) = "姓名"
.TextMatrix(0, 2) = " 基本工资"
.TextMatrix(1, 2) = " 基本工资"
.TextMatrix(0, 3) = " 津贴"
.TextMatrix(1, 3) = " 津贴"
.TextMatrix(0, 4) = " 车贴"
.TextMatrix(1, 4) = " 车贴"
.TextMatrix(0, 10) = "+其它 "
.TextMatrix(1, 10) = "+其它 "
.TextMatrix(0, 11) = " 应付工资"
.TextMatrix(1, 11) = " 应付工资"
.TextMatrix(0, 17) = "养老统筹"
.TextMatrix(1, 17) = "养老统筹"
.TextMatrix(0, 18) = "-其它 "
.TextMatrix(1, 18) = "-其它 "
.TextMatrix(0, 19) = " 实发工资"
.TextMatrix(1, 19) = " 实发工资"
.MergeRow(0) = True
.MergeRow(1) = True
For i = 0 To .Cols - 1
Select Case i
Case 0, 1, 2, 3, 4, 10, 11, 17, 18, 19
.MergeCol(i) = True
Case 5, 6, 7, 8, 9
.TextMatrix(0, i) = " 加班工资"
Case 12, 13, 14, 15, 16
.TextMatrix(0, i) = " 考勤违规扣除"
End Select
Next i
'列宽
For i = 0 To .Cols - 1
Select Case i
Case 0
.ColWidth(i) = 400
Case 1, 3, 4, 16, 17, 9
.ColWidth(i) = 780
Case 2, 11, 19
.ColWidth(i) = 930
Case 7, 12, 14
.ColWidth(i) = 470
Case 10, 18
.ColWidth(i) = 1200
Case 20
.ColWidth(i) = 1
Case 13, 15
.ColWidth(i) = 650
Case 5
.ColWidth(i) = 500
Case 6, 8
.ColWidth(i) = 720
End Select
Next i
'表头项居中
For i = 0 To .Cols - 2
Select Case i
Case 0, 1
.ColAlignment(i) = 4
Case 10, 18
.ColAlignment(i) = flexAlignRightCenter
Case Else
.ColAlignment(i) = 9
End Select
Next i
End With
End Sub
Private Sub Form_Load()
call fg_show
End sub
Private Sub Command1_Click()
fg.clear
call fg_show '这样是不是很简单 :)
End sub
Sub fg_Show() '定义表头,这个表头够复杂吧?呵呵
Dim i As Integer
Dim s As String
With fg
.Cols = 21
.FormatString = s
.TextMatrix(1, 5) = "小时"
.TextMatrix(1, 6) = " 小计"
.TextMatrix(1, 7) = "天数"
.TextMatrix(1, 8) = " 小计"
.TextMatrix(1, 9) = " 合计"
.TextMatrix(1, 12) = "次数"
.TextMatrix(1, 13) = " 小计"
.TextMatrix(1, 14) = "天数"
.TextMatrix(1, 15) = " 小计"
.TextMatrix(1, 16) = " 合计"
.TextMatrix(1, 20) = "id"
'合并表头
' .MergeCells = flexMergeRestrictColumns
.MergeCells = flexMergeFixedOnly
.TextMatrix(0, 0) = "序号"
.TextMatrix(1, 0) = "序号"
.TextMatrix(0, 1) = "姓名"
.TextMatrix(1, 1) = "姓名"
.TextMatrix(0, 2) = " 基本工资"
.TextMatrix(1, 2) = " 基本工资"
.TextMatrix(0, 3) = " 津贴"
.TextMatrix(1, 3) = " 津贴"
.TextMatrix(0, 4) = " 车贴"
.TextMatrix(1, 4) = " 车贴"
.TextMatrix(0, 10) = "+其它 "
.TextMatrix(1, 10) = "+其它 "
.TextMatrix(0, 11) = " 应付工资"
.TextMatrix(1, 11) = " 应付工资"
.TextMatrix(0, 17) = "养老统筹"
.TextMatrix(1, 17) = "养老统筹"
.TextMatrix(0, 18) = "-其它 "
.TextMatrix(1, 18) = "-其它 "
.TextMatrix(0, 19) = " 实发工资"
.TextMatrix(1, 19) = " 实发工资"
.MergeRow(0) = True
.MergeRow(1) = True
For i = 0 To .Cols - 1
Select Case i
Case 0, 1, 2, 3, 4, 10, 11, 17, 18, 19
.MergeCol(i) = True
Case 5, 6, 7, 8, 9
.TextMatrix(0, i) = " 加班工资"
Case 12, 13, 14, 15, 16
.TextMatrix(0, i) = " 考勤违规扣除"
End Select
Next i
'列宽
For i = 0 To .Cols - 1
Select Case i
Case 0
.ColWidth(i) = 400
Case 1, 3, 4, 16, 17, 9
.ColWidth(i) = 780
Case 2, 11, 19
.ColWidth(i) = 930
Case 7, 12, 14
.ColWidth(i) = 470
Case 10, 18
.ColWidth(i) = 1200
Case 20
.ColWidth(i) = 1
Case 13, 15
.ColWidth(i) = 650
Case 5
.ColWidth(i) = 500
Case 6, 8
.ColWidth(i) = 720
End Select
Next i
'表头项居中
For i = 0 To .Cols - 2
Select Case i
Case 0, 1
.ColAlignment(i) = 4
Case 10, 18
.ColAlignment(i) = flexAlignRightCenter
Case Else
.ColAlignment(i) = 9
End Select
Next i
End With
End Sub
Private Sub Form_Load()
call fg_show
End sub
Private Sub Command1_Click()
fg.clear
call fg_show '这样是不是很简单 :)
End sub
#12
学习
#13
仔细想来,觉得不执行clear还是不好的,因为这样表面上表格内容已经清了,但实际上单元格内还是有内容的,通过可以恢复内容就可以看出来,所以要想清空内容,就要执行clear,所以执行完clear,再重写一次表头是较好的办法.
个人拙见,不知对否?
个人拙见,不知对否?
#14
up
#15
使用for循环不是可以解决了吗?
with grid
for i=1 to .rows-1
for j=0 to .cols-1
.textmarry(i,j)=""
next
next
end with
with grid
for i=1 to .rows-1
for j=0 to .cols-1
.textmarry(i,j)=""
next
next
end with