如何可以使用vb在列记录的时候可以向excel一样的模式?

kingljx 2002-04-22 11:42:15
如题
...全文
43 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
sonicdater 2002-04-24
  • 打赏
  • 举报
回复
关键是 使用 ADO 的 PAGESIZE 属性 和 AbsolutePage 属性。
-------------------------------------------------------------------
下面的代码给你参考一下:
m1 是个 Grid 控件。

Function Getpagedate(ByVal TSQL As String, ByVal pagenumber As Integer, ByVal size As Integer) As Long
Screen.MousePointer = 11
Dim x As Integer

If rs1.State = 1 Then rs1.Close
rs1.CursorLocation = adUseClient
rs1.Open TSQL, conn1, adOpenForwardOnly, adLockReadOnly
If rs1.EOF Then
mg1.Rows = 1
mg1.Rows = mg1.Rows + 1
mg1.FixedRows = 1
Label2(4).Caption = "Record Count:" & "0" & " Page Count:" & "0"
Screen.MousePointer = 0
Exit Function
End If

mg1.Rows = 1
mg1.Cols = rs1.Fields.Count
rs1.PageSize = size
If pagenumber > rs1.PageCount Then
txtpn = 0
pagenumber = 1
ElseIf pagenumber <= 0 Then
txtpn = rs1.PageCount + 1
pagenumber = rs1.PageCount
End If
rs1.AbsolutePage = pagenumber
txtpn.Text = rs1.AbsolutePage
mg1.Visible = False
With mg1
Do While Not rs1.EOF And rs1.AbsolutePage = pagenumber
.Rows = .Rows + 1
.FixedRows = 1
For x = 0 To rs1.Fields.Count - 1
.TextMatrix(.Rows - 1, x) = IIf(IsNull(rs1.Fields(x).value), "", rs1.Fields(x).value)
If x = 4 Or x = 3 Then
.TextMatrix(.Rows - 1, x) = Format(.TextMatrix(.Rows - 1, x), "Fixed")
If Val(.TextMatrix(.Rows - 1, x)) = 0 Then .TextMatrix(.Rows - 1, x) = ""
.ROW = .Rows - 1: .COL = x
If Val(.TextMatrix(.Rows - 1, x)) < 0 Then .CellForeColor = vbRed Else .CellForeColor = vbBlue
End If
Next
rs1.MoveNext
Loop
Label2(4).Caption = "Record Count:" & CStr(rs1.RecordCount) & " Page Count:" & rs1.PageCount
Getpagedate = rs1.RecordCount
rs1.Close
Screen.MousePointer = 0
mg1.Visible = True
.Refresh
End With
End Function
sonicdater 2002-04-24
  • 打赏
  • 举报
回复
都可以。
kingljx 2002-04-24
  • 打赏
  • 举报
回复
那使用datagrid、msflexgrid、mshflexgrid,那一个可以把记录分页显示出来?
kingljx 2002-04-22
  • 打赏
  • 举报
回复
能不能具体点?
我是初学,不太明白
gump2000 2002-04-22
  • 打赏
  • 举报
回复
您可以参考MSDN例子:

C:\Program Files\Microsoft Visual Studio\MSDN\2001JUL\1033\SAMPLES\VB98\Msflexgd

可能由于您的MSDN版本不同、安装位置不同而不同
gump2000 2002-04-22
  • 打赏
  • 举报
回复
用Grid控件

DataGrid
MsFlexGrid
MshFlexGrid
....

sonicdater 2002-04-22
  • 打赏
  • 举报
回复
用 MSHFlexGrid .
先确定 数据所需的 行和列数.
在用 .TextArray 填加数据
With MSHFlexGrid
.Rows = xxx
.Cols = xxx
'//从 数据集 读如数据并填充
Do Until Rs.Eof
For I =0 To (.Rows-1)
For J=0 To (.Cols -1)
.TextArray(faIndex(I,J)) = Rs.Fields("Data").Value
Next
Next
Loop
End with

关于 faIndex 函数, MSDN 上已有.

7,759

社区成员

发帖
与我相关
我的任务
社区描述
VB 基础类
社区管理员
  • VB基础类社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧