MSFlexGrid有许多属性搞得我云里雾里的,现向大家请教
colpos rowpos
colposition rowposition
colsel rowsel
mousecol mouserow
leftcol topcol
还有好多哦,哪位大侠指点一下,具体的使用情况同时欢迎大家提供一些使用MSFlexGrid的技巧,谢谢
colpos rowpos
colposition rowposition
colsel rowsel
mousecol mouserow
leftcol topcol
还有好多哦,哪位大侠指点一下,具体的使用情况同时欢迎大家提供一些使用MSFlexGrid的技巧,谢谢
【CSDN教官】教官还要求救吗???
Public Sub GridInit()
Dim rs As ADODB.Recordset
Dim strsql As String
With frmdc.dcGrid
.Clear
.Cols = 6
.Rows = 1
.ColWidth(0) = 200
.ColWidth(1) = 1500
.ColWidth(2) = 1500
.ColWidth(3) = 3000
.ColWidth(4) = 100
.ColWidth(5) = 1500
.Row = 0
.Col = 1
.Text = "今日菜单编号"
.Col = 2
.Text = "菜肴编号"
.Col = 3
.Text = "菜名"
.Col = 4
.Text = "菜价"
.Col = 5
.Text = "数量"
Set rs = New ADODB.Recordset
If lb = "all" Then
strsql = "select * from day_menu where addtime=#" & Date & "#"
Else
strsql = "select * from day_menu where addtime=#" & Date & "# and class2_id='" & lb & "'"
End If
Set rs = m_Connect.getAdodbRecordset(strsql)
If rs.RecordCount > 0 Then
rs.MoveFirst
End If
Do While Not rs.EOF And Not rs.BOF
.AddItem Chr(9) & rs("autoid") & Chr(9) & rs("cybm") & Chr(9) & rs("food_name") & Chr(9) & rs("food_price") & Chr(9) & rs("food_number")
rs.MoveNext
Loop
End With
rs.Close
Set rs = Nothing
End Sub
Private Sub Command1_Click()
MSF.RowHeight(1) = 0
End Sub' 隐藏第一列
Private Sub Command2_Click()
MSF.ColWidth(1) = 0
End Sub' 显示所有的行和列
Private Sub Command3_Click()
MSF.RowHeight(1) = MSF.RowHeight(2)
MSF.ColWidth(1) = MSF.ColWidth(2)
End Sub' 初始化MSFlexGrid
Private Sub Form_Load()
Dim i As Integer
MSF.Rows = 0
For i = 0 To 10
MSF.AddItem "AA" + Str(i)
Next i
For i = 0 To 10
MSF.Col = 1
MSF.Row = i
MSF.Text = CStr(i)
MSF.Col = 2
MSF.Row = i
MSF.Text = CStr(i) & CStr(i)
MSF.Col = 3
MSF.Row = i
MSF.Text = CStr(i) & CStr(i) & CStr(i)
Next i
End Sub
Option Explicit' 初始化界面
Private Sub Form_Load()
Dim i As Integer
With MSFlexGrid1
.Cols = 6
.Rows = 10
For i = 0 To 9
.RowHeight(i) = 300
Next i
.TextMatrix(0, 0) = "学号\科目"
.TextMatrix(0, 1) = "数学"
.TextMatrix(0, 2) = "语文"
.TextMatrix(0, 3) = "英语"
.TextMatrix(0, 4) = "政治"
.TextMatrix(0, 5) = "历史"
.TextMatrix(1, 0) = "0201001"
.TextMatrix(2, 0) = "0201002"
.TextMatrix(3, 0) = "0201003"
.TextMatrix(4, 0) = "0201004"
.TextMatrix(5, 0) = "0201005"
.TextMatrix(6, 0) = "0201006"
.TextMatrix(7, 0) = "0201007"
.TextMatrix(8, 0) = "0201008"
.TextMatrix(9, 0) = "0201009"
End With
Label1.Caption = "在选中项双击或单击回车输入成绩,完毕按回车,分数输入MSFlexGrid" & vbCr & _
"而按下Esc键则取消输入..."
End Sub' 双击表格时,显示文本框用于输入
Private Sub MSFlexGrid1_DblClick()
Dim c As Integer, r As Integer
With MSFlexGrid1
c = .Col: r = .Row
Text1.Left = .Left + .ColPos(c)
Text1.Top = .Top + .RowPos(r)
Text1.Width = .ColWidth(c)
Text1.Height = .RowHeight(r)
Text1 = .Text
Text1.Visible = True
Text1.SetFocus
End With
End Sub' 单击回车键时,实现和双击鼠标相同的处理
Private Sub MSFlexGrid1_KeyPress(KeyAscii As Integer)
If KeyAscii = vbKeyReturn Then
Call MSFlexGrid1_DblClick
End If
End SubPrivate Sub Text1_KeyPress(KeyAscii As Integer)
' ESC取消输入
If KeyAscii = vbKeyEscape Then
Text1.Visible = False
MSFlexGrid1.SetFocus
Exit Sub
End If
' 回车确定输入
If KeyAscii = vbKeyReturn Then
MSFlexGrid1.Text = Text1.Text
Text1.Visible = False
MSFlexGrid1.SetFocus
End If
End SubPrivate Sub Text1_LostFocus()
Text1.Visible = False
MSFlexGrid1.SetFocus
End Sub
Dim mes As MSFlexGrid
Dim i As Integer
With mes
.Cols = 8
.Rows = 6
.FixedCols = 0
For i = 0 To 5
.RowHeight(i) = 300
Next i
.TextMatrix(0, 0) = "借书证编号"
.TextMatrix(0, 1) = "读者姓名"
.TextMatrix(0, 2) = "图书编号"
.TextMatrix(0, 3) = "书名"
.TextMatrix(0, 4) = "价格"
.TextMatrix(0, 5) = "类别"
.TextMatrix(0, 6) = "出版社"
.TextMatrix(0, 7) = "借出日期"
End With
出现数据变量或with变量未定义的错误
你的MES还没实例化呢
以下的语句
Dim mes As MSFlexGrid
改成
Dim mes As new MSFlexGrid
或者改成
Dim mes As MSFlexGrid
set mes = new msflexgrid
Dim i, j As Integer
Dim Max As Double
With MSFlexGrid1
For i = 0 To .Cols - 1
Max = 0
If .ColWidth(i) <> 0 Then
For j = 0 To .Rows - 1
If Me.TextWidth(.TextMatrix(j, i)) > Max Then
Max = Me.TextWidth(.TextMatrix(j, i))
End If
Next
.ColWidth(i) = Max + 110
End If
Next
End With
Private Sub Command1_Click()
Dim I As Integer, J As Integer msfgrid.Rows = 12000
msfgrid.Cols = 30
End Sub
具体可以参考文档中心一文中的用法
http://www.csdn.net/Develop/read_article.asp?id=24771colposition rowposition 可用来移动行或列colsel rowsel 返回或设置一定范围的单元格的起始列(行)或终止列(列)mousecol mouserow 按行或列坐标返回鼠标的当前位置leftcol topcol 返回或设置最左边(上边)可见的不固定列(行)