msflexgrid跟datagrid不同,不支持修改,连数据集都要自己写代码填充
请问哪为有填充的代码让小弟参考一下!
msflexgrid的筛选代码又是怎么样?
msflexgrid的导出到excel代码又是怎么样?
还有就是双击msflexgrid中的一行(这是一个概括的内容)弹出一个明细的窗口的代码又是怎么样呢?
请问哪为有填充的代码让小弟参考一下!
msflexgrid的筛选代码又是怎么样?
msflexgrid的导出到excel代码又是怎么样?
还有就是双击msflexgrid中的一行(这是一个概括的内容)弹出一个明细的窗口的代码又是怎么样呢?
解决方案 »
- 怎么用VB登录有验证码的网站?
- ADO数据源的简单问题,简单的跟白送分一样了。(帮顶有分啊)
- 保存图片框中的文本框
- 如何让我的ocx控件在嵌入html后可以列出<param name=...>
- 高手帮忙,如何在网吧里得到代理服务器的IP地址,就是连上宽带的那个IP地址。
- 如何改变文件夹和其中文件的只读属性!
- 高分请高手,小问题拿大分,不够再加,大家都来看一下,互相学习!
- 哪里有VB的書籍下載?
- vb与Vb.net到底有什么区别呢??/?
- 一sql数据库中有3 个表。在一MDI窗体中有若干个子窗体。如何用ADO控件代码对数据库中的3 个表建立连接后,在子窗体中分别调用相应的连接。
- VB中引用ocx控件,是静态载入该控件的吗?
- adodc控件向数据库表中添加数据的问题?
rs.open "select * from 表名",conn,adopenkeyset,adlockreadonly
set msflexgrid.datasource=rs
这个是错的,因为msflexgrid不像datagrid那样设置的
上两天是我搞错了,我运行的时候是mshflexgrid,用set msflexgrid.datasource=rs运行时报错的
datagrid如何做到查找功能?
http://topic.csdn.net/u/20090909/11/a36762cd-2284-4522-95fa-acfe52fe40cc.html?92099
回答你几个问题如下:1、msflexgrid可以与data控件在设计时绑定,而不能动态与data控件绑定。
也就是说可以在msflexgrid的属性框里的datasource里选择data1,
而运行时这样绑定是错误的:set msflexgrid = data12、msflexgrid根本就不能与ADO绑定。
也就是说set msflexgrid.datasource=rs这句对msflexgrid来说根本就是错误的,
rs是ADODB的数据集,属于ADO(星星们作答时要谨慎一些,不要误导初学者)。3、请问哪位有填充的代码让让小弟参考一下:Option Explicit
Dim cnn As New ADODB.Connection
Dim rst As New ADODB.RecordsetPrivate Sub Command1_Click() 'MSFlexGrid编程填充方式
Dim dbpath As String, sql_Str As String
Dim rCount As Long, fCount As Integer
dbpath = App.Path & IIf(Len(App.Path) > 3, "\" & "wgbc.mdb", "wgbc.mdb")
cnn.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & _
dbpath & ";Persist Security Info=False"
cnn.CursorLocation = adUseClient
cnn.Open
sql_Str = "SELECT * from ip" '-----------从IP表取记录的SQL语句
Set rst = cnn.Execute(sql_Str) '---------取记录存入rst记录集
fCount = rst.Fields.Count '--------------统计字段数
With MSFlexGrid1
.Cols = fCount
Dim r As Long, f As Integer
For f = 0 To fCount - 1
.TextMatrix(0, f) = rst(f).Name '填充字段名
Next
Do While Not rst.EOF '--------------填充记录内容
For f = 0 To fCount - 1
.TextMatrix(.Rows - 1, f) = rst(f)
Next
.Rows = .Rows + 1
rst.MoveNext
Loop
End With
rst.Close: cnn.Close
End Sub4、msflexgrid的筛选代码又是怎么样?
请用SQL语句筛选,然后再重新填充msflexgrid
涉及到MSFlexGrid1.Clear该方法清除 MSHFlexGrid 的内容。这包括所有文本、图片和单元格式。Clear 方法并不影响 MSHFlexGrid 上的行数和列数,注意按前面的方法修正。5、msflexgrid的导出到excel代码又是怎么样?Private Sub Command2_Click()
On Error GoTo iErr
Dim iFileName As String
CommonDialog1.CancelError = True
CommonDialog1.FileName = "电参数" & DTPicker1(0).Value & "至" & DTPicker1(1).Value
CommonDialog1.Filter = "All Files|*.xls"
CommonDialog1.Action = 2
iFileName = CommonDialog1.FileName
If iFileName = "" Then
Exit Sub
Else
writeExcel iFileName
End If
Exit SubiErr:
Err.Clear
MsgBox "用户取消操作!", vbOKOnly, "取消操作"End Sub
Private Sub writeExcel(Filename1 As String) 'mhg2看作msflexgrid
On Error GoTo myErr
Dim FilePath As String, tmp As Byte
Dim excel_app As Object
'建立 Excel 应用程序
Set excel_app = CreateObject("Excel.Application")
'显示Excel应用程序
'excel_app.Visible = True
'添加新工作簿:
excel_app.workbooks.Add
If Dir(Filename1) <> "" Then
tmp = MsgBox(FilePath & "文件已经存在,是否覆盖?", _
vbYesNo, "文件已经存在")
If tmp = 6 Then
Kill Filename1
Else
GoTo myErr
End If
End If
DoEvents
Screen.MousePointer = vbHourglass
'设置第1个工作表为活动工作表:
excel_app.Sheets("sheet1").Select
Const Lk As Integer = 10
Const Lk1 As Integer = 16
'设置指定列的宽度(单位:字符个数)及对齐方式
excel_app.ActiveSheet.Columns(1).ColumnWidth = 25
excel_app.ActiveSheet.Columns(2).ColumnWidth = 20
excel_app.ActiveSheet.Columns(3).ColumnWidth = Lk
excel_app.ActiveSheet.Columns(4).ColumnWidth = Lk
excel_app.ActiveSheet.Columns(5).ColumnWidth = Lk
excel_app.ActiveSheet.Columns(6).ColumnWidth = Lk
excel_app.ActiveSheet.Columns(7).ColumnWidth = Lk
excel_app.ActiveSheet.Columns(8).ColumnWidth = Lk
excel_app.ActiveSheet.Columns(9).ColumnWidth = Lk1
excel_app.ActiveSheet.Columns(10).ColumnWidth = Lk1
excel_app.ActiveSheet.Columns(11).ColumnWidth = Lk1
excel_app.ActiveSheet.Columns(12).ColumnWidth = Lk
excel_app.ActiveSheet.Columns(13).ColumnWidth = Lk
excel_app.ActiveSheet.Columns(14).ColumnWidth = Lk
excel_app.ActiveSheet.Columns("B:B").NumberFormatLocal = "@" Dim tmpNum As Byte
For tmpNum = 2 To 14
With excel_app.ActiveSheet
'4右对齐,3居中
.Columns(tmpNum).HorizontalAlignment = -4152
End With
Next tmpNum
'设置页面为横向
excel_app.ActiveSheet.PageSetup.Orientation = 2
'添加标题
excel_app.ActiveSheet.Range(excel_app.ActiveSheet.Cells(1, 1), excel_app.ActiveSheet.Cells(1, 14)).Merge
excel_app.Cells(1, 1) = "电网参数表"
excel_app.ActiveSheet.Cells(1, 1).HorizontalAlignment = -4108 excel_app.ActiveSheet.Cells.Font.Name = "宋体"
excel_app.ActiveSheet.Cells.Font.Size = 9
excel_app.ActiveSheet.Cells.RowHeight = 20
'添加数据表内容
Dim iiRow As Integer
Dim iiCol As Integer
iiRow = 0: iiCol = 0
Do While iiRow < mhg2.Rows
Do While iiCol <= mhg2.Cols - 1
mhg2.Row = iiRow
excel_app.Cells(iiRow + 3, 1 + iiCol) = mhg2.TextMatrix(mhg2.Row, iiCol)
iiCol = iiCol + 1
DoEvents
Loop
iiCol = 0
iiRow = iiRow + 1
DoEvents
Loop
excel_app.ActiveSheet.Range(excel_app.ActiveSheet.Cells(3, 1), excel_app.ActiveSheet.Cells(3, 14)).HorizontalAlignment = -4108 '设置页面和套表框
Dim tmp_fw As String
tmp_fw = "A3:N" & Format(iiRow + 2)
With excel_app.ActiveSheet.Range(tmp_fw).Borders
.LineStyle = 1
.Weight = 2
End With
excel_app.ActiveSheet.Range("A3").Select
'工作表另存为:
If Not excel_app.ActiveWorkBook.Saved Then
excel_app.ActiveWorkBook.SaveAs FileName:=Filename1
End If
' Close Excel.
excel_app.Quit
Set excel_app = Nothing Screen.MousePointer = vbDefault
MsgBox "导出了" & Format$(iiRow - 1) & "条记录", , "导出成功"
Exit Sub
myErr:
If Err.Number = 429 Then
Screen.MousePointer = vbDefault
MsgBox "请先安装EXCEL!", , "导出错误"
Exit Sub
End If
excel_app.DisplayAlerts = False '关闭时不提示保存
excel_app.Quit '关闭EXCEL
excel_app.DisplayAlerts = True '关闭时提示保存
Set excel_app = Nothing
Me.MousePointer = 0
If tmp <> 7 Then MsgBox " 导出数据到 Excel 时出错! ", , "导出错误"End Sub
6、还有就是双击msflexgrid中的一行(这是一个概括的内容)弹出一个明细的窗口的代码又是怎么样呢?Private Sub MSFlexGrid1_DblClick()
Dim i As Integer, temp As String
With MSFlexGrid1
For i = 0 To .Cols - 1
temp = temp & .TextMatrix(.Row, i) & ","
Next
End With
temp = Left(temp, Len(temp) - 1)
MsgBox temp, vbInformation, "明细的窗口"
End Sub
建议楼主放弃MSFlexGrid控件,改用MSHFlexGrid控件MSHFlexGrid控件,可以与ADO直接绑定,而且比MSFlexGrid控件多了一些功能,大多属性与MSFlexGrid控件类似。使用MSHFlexGrid控件可以如下这样:
set mshflexgrid1.datasource=rs