要程序的代码是:Dim i, j, k As Integer
1、设置行列数
With MSHFlexGrid1
.Rows = 5
.Cols = 5
End With
2、添加表头
MSHFlexGrid1.Row = 0
For i = 1 To MSHFlexGrid1.Cols - 1
MSHFlexGrid1.Col = i
MSHFlexGrid1.Text = "列" &i
Next
3、添加记录
k = 1
For i = 1 To MSHFlexGrid1.Rows - 1
For j = 1 To MSHFlexGrid1.Cols - 1
MSHFlexGrid1.Row = i
MSHFlexGrid1.Col = j
MSHFlexGrid1.Text = k
k = k + 1
Next
Next
说明:添加部件"Microsoft Hierarchical FlexGrid Control 6.0 (OLEDB)"才能使用MSHFlexGrid.
VB6.0可使用绑定到数据源、使用AddItem方法添加数据或逐一单元格添加数据,来向
MSFlexGrid控件添加数据。
1)使用绑定到数据源。
可使用ADODB数据源或Data控件绑定MSFlexGrid控件。
2)使用AddItem方法添加数据。
AddItem 方法 (MSHFlexGrid),该方法将一个行添加到 MSHFlexGrid 控件中。
Private Sub Command1_Click()MSFlexGrid1.Cols = 5
MSFlexGrid1.AddItem vbTab & "1" & vbTab & "2" & vbTab & "3" & vbTab & "4"
MSFlexGrid1.AddItem vbTab & "5" & vbTab & "6" & vbTab & "7" & vbTab & "8"
MSFlexGrid1.AddItem vbTab & "9" & vbTab & "10" & vbTab & "11" & vbTab & "12"
MSFlexGrid1.AddItem vbTab & "13" & vbTab & "14" & vbTab & "15" & vbTab & "16"
MSFlexGrid1.RemoveItem (1) '删除默认空白行
End Sub 3)逐一单元格添加数据。
Private Sub Command2_Click()
Dim i, j, k As Integer
'设置行列数
With MSFlexGrid1
.Rows = 5
.Cols = 5
End With
'添加表头
MSFlexGrid1.Row = 0
For i = 1 To MSFlexGrid1.Cols - 1
MSFlexGrid1.Col = i
MSFlexGrid1.Text = "列" & i
Next
'添加记录
k = 1
For i = 1 To MSFlexGrid1.Rows - 1
For j = 1 To MSFlexGrid1.Cols - 1
MSFlexGrid1.Row = i
MSFlexGrid1.Col = j
MSFlexGrid1.Text = k
k = k + 1
Next
Next
End Sub
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)