首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > VB >

以表格的形式输出 ,指定字段内容?解决思路

2012-01-02 
以表格的形式输出 ,指定字段内容????例如有两个字段id 和 name把字段id以表格的形式展示出来格式例子12345

以表格的形式输出 ,指定字段内容????
例如有两个字段id 和 name

把字段id以表格的形式展示出来
格式例子

1 2 3 4 5 6 7 8 9 10
11 12 13 14 15 16 17 18 19 20 
21 22 23 24 25 26 27 28 29 30
31 .......

当鼠标单击数字时 text1里面就会显示id所对应的name字段内容

怎么做???(字段id是横向排序的哦)

[解决办法]
'使用MSHFlexGrid控件
'设置列数(固定,假设为mc,不含固定列)

Dim RS As ADODB.Recordset

Private Sub Command1_Click()
Dim r As Long, c As Long

With RS
If .RecordCount > 0 Then
.MoveFirst
c = 1
r = 1
While Not .EOF
If c > MC Then
r = r + 1
c = 1
MSHFlexGrid1.AddItem '添加一行
End If
MSHFlexGrid1.TextMatrix(r, c) = CStr(RS("ID字段名称"))

c = c + 1
.MoveNext
Wend
End If
End With
End Sub
[解决办法]

VB code
Private Sub Form_Load()With MSHFlexGrid1   .Width = 3350   .FixedCols = 0   .FixedRows = 0   .Cols = 10   .Rows = 150      .ColWidth(-1) = 300   End WithWith Adodc1   .ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\db1.mdb;Persist Security Info=False"   .RecordSource = "select * from tb1"   .Refresh    MSHFlexGrid1.Rows = Int(.Recordset.RecordCount / 10 + 0.9)      Dim r As Long, c As Integer   While Not .Recordset.EOF      MSHFlexGrid1.TextMatrix(r, c) = .Recordset.Fields(0)      c = c + 1      If c > 9 Then c = 0: r = r + 1      .Recordset.MoveNext   Wend End WithEnd SubPrivate Sub MSHFlexGrid1_Click()    Text1 = ""    Adodc1.Recordset.Find "ID=" & Val(MSHFlexGrid1.Text) & "", , , 1    If Not Adodc1.Recordset.EOF Then Text1 = Adodc1.Recordset.Fields(1)    End Sub 

热点排行