VSFlexgrid、MSFlexGrid控件的技术问题
1,如果想把某一列设置成下拉匡中选择,只能写成 grid.colcombolist(1) = "a|b|c" 吗?能不能把下拉框中的数据和 recordset 或数组绑定。
答案:grid.colcombolist(1)=grid.buildcombolist(rs!abc)
2,怎样限定第三列可编辑,其他列不可编辑?
答案:
Private Sub fg_BeforeEdit(ByVal Row As Long, ByVal Col As Long, Cancel As Boolean)
'*******先将设editable=2
'限定不可编辑列,如有5列
If Col = 0 Then Cancel = True
If Col = 1 Then Cancel = True
If Col = 2 Then Cancel = True
If Col = 4 Then Cancel = True
If Col = 5 Then Cancel = True
End Sub
3、怎么获得当前单元个的位置,比如某单元个获得焦点,弹出msgbox("你选的是第4行第5列")
Answer:
Private Sub VSFlexGrid1_Click()
Dim a, b As Long
a = VSFlexGrid1.Row
b = VSFlexGrid1.Col
MsgBox "你选的是" & a & "行" & b & "列"
End Sub
4,对vsflexgrid进行编辑的时候,让vsflexgrid的某列只能输入数字?
Answer:
Private Sub CheckData(KeyAscii As Integer)
If KeyAscii >= 48 And KeyAscii <= 57 Then Exit Sub '如果是数字退出
If KeyAscii <> 8 Then KeyAscii = 0
End Sub
Private Sub vsflexgrid_KeyPressEdit(ByVal Row As Long, ByVal Col As Long, KeyAscii As Integer)
If col=1 Then '第一列只能输入数字
CheckData KeyAscii
End If
End Sub
5,限制某列只能输入数字
Answer:
Private Sub fg_KeyPressEdit(ByVal Row As Long, ByVal Col As Long, KeyAscii As Integer)
Dim Numbers As String '允许输入的字符
If fg.Col = 6 Then '第6列
Numbers = "1234567890" + Chr(46) + Chr(8)
If InStr(Numbers, Chr(KeyAscii)) = 0 Then
KeyAscii = 0
End If
End If
End Sub
6,如何指定一列的输入格式
例如:显示有小数点后3位(是整数的话显示.000;没有达到3位显示.200(追加0);超过的4舍五入)
Answer:
if fg.col=5 then '第五行
for i=1 to fg.rows-1
fg.TextMatrix(i,5)=format(fg.TextMatrix(i,5),"##0.000")
next i
end if
7,在一个单元格输入好数字回车,下一单元格(或者下一行第一个)自动获得焦点。
这个怎么实现?
Answer:
试试这个,,,,,
' With fg
' If .Col = .Cols - 1 Then
' '如果到了最右边的列就跳到下一行第一个可非固定列
' '.Row = Row + 1
' .Col = .FixedCols
' Else
' '向右移动一列
' .Col = Col + 1
' End If
' End With
8,最下面的合计的那一行是怎么加的??希望楼主指点一下,谢谢!
Ansewr:
合计行添加代码:
'*****************************************
'显示计算合计行
.Rows = .Rows + 1
Dim r&, c&, tot!
For c = 1 To .Cols - 1
tot = 0
For r = 1 To .Rows - 2
tot = tot + .valueMatrix(r, c)
Next
.TextMatrix(r, c) = tot
Next
'*****************
,'在合计头列标明合计,合并单元格
' For I = 0 To 1
.TextMatrix(.Rows - 1, 0) = "合 计"
' .FixedAlignment(I) = 4
' Next
.MergeCells = flexMergeFixedOnly
.MergeRow(r) = True
9,怎么样点击一条VSFlexgrid控件里的记录时下面的TEXT控件就显示相应的内容?
Ansewr:
text1=fg.TextMatrix(fg.RowSel, 2) '显示第二列信
10,如果想把某一列设置成下拉匡中选择,只能写成 grid.colcombolist(1) = "a|b|c" 吗?能不能把下拉框中的数据和 recordset 或数组绑定。
Answer:
grid.colcombolist(1)=grid.buildcombolist(rs!abc)
11,我用的是VsFlexGrid 8
如何把表格里面的Name变成我指定的文字,
以前用的是DataGrid,实现的方法是DataGrid1.Columns.Caption="名字"
现在学用VsFlexGrid,请高手指点.
Answer:
我来了,这段时间实在太忙了,,,没能及时回答大家的问题,,,,
指定name可以这样表示:
vfg.TextMatrix(0,1)="我的名字"
12,如何让我选择的不是一个框,而是一整行,还有就是如何能把我选择的这一行的第一个框里的字添加到text1.text里.
Answer:
1,有一个属性可以让你的选择是一行的.
SelectionMode=1
2,text1=fg.TextMatrix(fg.RowSel,1)
在click事件里实现
13,运行时如何调整调行或列宽度?
Answer:
AllowUserResizing=1 '可调列
AllowUserResizing=2 '可调行
AllowUserResizing=3 '可调行和列
转自百度空间http://hi.baidu.com/jysse/blog/item/b6e79d52d307430e0cf3e352.html