关于mshflexgrid控件的问题?谢谢指点!!

liuwangxin 2004-10-24 11:36:08
请问mshflexgrid控件怎样与ado控件动态绑定?
同时mshflexgrid控件怎么用书写代码来改变列宽?
请智者指点...
...全文
107 点赞 收藏 3
写回复
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
风之浪漫 2004-10-24
动态填充Msflexgrid,这个是VB。NET的代码,你自已改一下吧!~
调用时,在FillMsGrid 的后边要加上你所用的Msflexgrid的名称,及Recordset名称

Public Sub FillMsGrid(ByVal MSGrid As MSFlexGridLib.AxMSFlexGrid, ByVal rs As ADODB.Recordset) '数据库全部填充到表格中
Dim rCount As Integer
Dim i As Integer
Dim j As Integer
Dim cCount As Integer
cCount = rs.Fields.Count
rCount = rs.recordcount
With MSGrid
'设置行数
If rCount = 0 Then
.Rows = 1
Else
.Rows = rCount + 1
End If
'设置列数
.Cols = cCount
'设置固定列的名及对齐方式
For i = 0 To cCount - 1
.set_ColAlignment(i, 1)
.set_TextMatrix(0, i, rs(i).Name)
Next
'将数据库中的数据导入到表格中
j = 1
Do While Not rs.EOF
For i = 0 To cCount - 1
.set_TextMatrix(j, i, CStr(rs(i).Value))
Next
rs.MoveNext()
j = j + 1
Loop
End With
End Sub
回复
daisy8675 2004-10-24
Option Explicit

Public Rs As New ADODB.Recordset
Public Conn As New ADODB.Connection

Public Sub Make_Connection()
Dim strConn As String
strConn = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & App.Path & "\People.mdb;Persist Security Info=False"

Conn.CursorLocation = adUseClient
Conn.Open strConn

End Sub

Private Sub Form_Load()
Call Make_Connection


If Rs.State <> adStateClosed Then Rs.Close
Rs.Open "Select * from Man", Conn, adOpenStatic, adLockOptimistic

Set Me.MSHFlexGrid1.DataSource = Rs

With Me.MSHFlexGrid1
.ColWidth(1) = 500
.ColWidth(2) = 600
End With
End Sub
回复
风之浪漫 2004-10-24
1 ...MSFLEXGRID不能和ADO控件绑定。
但可以用代码实现1~

2。改变列宽:msflexgrid1.ColWidth (i)=2222
回复
发动态
发帖子

1180

社区成员

VB 数据库(包含打印,安装,报表)
申请成为版主
社区公告
暂无公告