VSFlexGrid控件属性和常用方法 三

将数字转换为大写金额的函数:
Function CurrencyToStr(ByVal Number As Currency) As String
   Number = Val(Trim(Number))
   If Number = 0 Then CurrencyToStr = "": Exit Function
   Dim str1Ary As Variant, str2Ary As Variant
   str1Ary = Split("零 壹 贰 叁 肆 伍陆柒 捌 玖")
   str2Ary = Split("分 角 元 拾 佰 仟万拾 佰 仟 亿 拾 佰 仟 万 拾 佰")
   Dim a As Long, b As Long   '循环基数
   Dim tmp1 As String         '临时转换
   Dim tmp2 As String         '临时转换结果
   Dim Point As Long          '小数点位置
   If Number <= -922337203685477# or Number >= 922337203685477# Then
      Exit Function
   End If
    tmp1 = Round(Number, 2)
    tmp1 = Replace(tmp1, "-", "")   '先去掉“-”号
    Point = InStr(tmp1, ".")        '取得小数点位置
    If Point = 0 Then       '如果有小数点,最大佰万亿
       b = Len(tmp1) + 2    '加2位小数
    Else
       b = Len(Left(tmp1, Point + 1))   '包括点加2位小数
    End If
    ''先将所有数字替换为中文
    For a = 9 To 0 Step -1
        tmp1 = Replace(Replace(tmp1, a, str1Ary(a)), ".", "")
    Next
    For a = 1 To b
        b = b - 1
        If Mid(tmp1, a, 1) <> "" Then
           If b > UBound(str2Ary) Then Exit For
           tmp2 = tmp2 & Mid(tmp1, a, 1) & str2Ary(b)
        End If
    Next
    If tmp2 = "" Then CurrencyToStr = "": Exit Function
    ''〓下面为非正式财务算法,可以去掉〓
    For a = 1 To Len(tmp2)
        tmp2 = Replace(tmp2, "零亿", "亿零")
        tmp2 = Replace(tmp2, "零万", "万零")
        tmp2 = Replace(tmp2, "零仟", "零")
        tmp2 = Replace(tmp2, "零佰", "零")
        tmp2 = Replace(tmp2, "零拾", "零")
        tmp2 = Replace(tmp2, "零元", "元")
        tmp2 = Replace(tmp2, "零零", "零")
        tmp2 = Replace(tmp2, "亿万", "亿")
    Next
    ''〓上面为非正式财务算法,可以去掉〓
    If Point = 1 Then tmp2 = "零元" + tmp2
    If Number < 0 Then tmp2 = "负" + tmp2
    If Point = 0 Then tmp2 = tmp2 + "整"
   CurrencyToStr = tmp2
End Function
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
Cell 属性的使用:
Cell 的作用是给以选定区块的特定的设置值,具体值可参阅相应属性值。
语法:Cell(条件准则, Row1, Col1, Row2, Col2) = 相应准则值
其中的“条件准则”有以下准则常数,根据准则的不同而设置相应准则的值:
flexcpAlignment         对齐方式
flexcpBackColor         背景色
flexcpChecked           选择框
flexcpCustomFormat      格式设置
flexcpData              日期
flexcpFloodColor        颜色
flexcpFloodPercent      背景色
flexcpFont              字体
flexcpFontBold          粗体
flexcpFontItalic        斜体
flexcpFontName          字体名
flexcpFontSize          字体大小
flexcpFontStrikethru    删除线
flexcpFontUnderline     下划线
flexcpFontWidth         字符宽
flexcpForeColor         字符色
flexcpHeight            高
flexcpLeft              左
flexcpPicture           添加图
flexcpPictureAlignment 图对齐
flexcpRefresh           刷新
flexcpSort              分类
flexcpText              字符
flexcpTextDisplay       显示字符
flexcpTextStyle         文本样式
flexcpTop               返回顶端高,同 RowPos 和 valueMatrix 属性
flexcpvalue             返回字符值
flexcpVariantvalue      返回字符值
flexcpWidth             返回单元宽

flexSTSum 方法:每行增加小计行[这个方法还不会用]语法:
VSG.flexSTSum 常数名,
[GroupOn As Long], :标签列
[TotalOn As Long], :计算列
[Format As String], :格式,例 "$0.00"
[BackColor As Color], :Color
[ForeColor As Color], :Color
[FontBold As Boolean], :False|True
[Caption As String], :例 "数 %s"
[MatchFrom As Integer], :0|1|2|3
[TatalOnly As Boolean] :False|True
常数名:
常数             常数值   说明
flexSTNone       0        大纲唯一的,没有合计价值
flexSTClear      1        清除全部的小计
flexSTSum        2        总数
flexSTPercent    3        总数的百分比
flexSTCount      4        行数
flexSTAverage    5        平均
flexSTMax        6        最大的
flexSTMin        7        最小的
flexSTStd        8        标准偏差
flexSTVar        9        方差
━━━━━━━━━
MousePointer、MouseIcon 鼠标指针的应用:
0=flexDefault
1=flexArrow
2=flexCross
3=flexIBeam
4=flexIcon
5=flexSize
6=flexSizeNESW
7=flexSizeNS
8=flexSizeNWSE
9=flexSizeEW
10=flexUpArrow
11=flexHourglass
12=flexNoDrop
13=flexArrowHourGlass
14=flexArrowQuestion
15=flexSizeAll
50=flexPointerCopy   '(&H32) '拖动带拷贝
51=flexPointerMove   '(&H33) '拖动
52=flexSizeHorz   '(&H34) '左右调整
53=flexSizeVert   '(&H35) '上下调整
54=flexHand   '(&H36) 手型
99=flexCustom '自定义
Const MA = "50,51,52,53,54"
Dim xy As Integer
xy = Val(Text1.Text)
If xy > 15 And xy <> 99 And InStr(MA, xy) = 0 Then xy = 15
VSG1.MousePointer = xy
If xy = 99 Then
    VSG1.MouseIcon = LoadPicture("C:/icon/Icon.ico")
End If
━━━━━━━━
单击列头将列互相拖动调换:
方法一:
VSG1.ExplorerBar = flexExMove   '2 这是最简单的方法了
注意这个属性在VB属性表中只设置了0、1、2、3、5、7、8种常数值
ExplorerBar 属性(value=0|1|2|3|5|7|8):
   0-flexExNone:默认,单击列头选择整列,单击行头选择整行
   1-flexExSort:单击列头可正反排序该列,单击行头选择整行
   2-flexExMove:单击列头可交换列顺序,单击行头选择整行
   3-flexExSortAndMove:具有 1 和 2 的功能
   4:单击列头可正反排序该列并在列头显示相应箭头,单击行头选择整行
   5-flexExSortShow:好像与 4 相同也
   6:具有 2 和 4 的功能
   7-flexExSortShowAndMove:好像与 6 相同也
   8-flexExMoveRows:单击列头选择整列,可拖动行
   9:单击列头可正反排序该列,可拖动行
   10:可拖动行与列
   11:可排序列及拖动行列
   12:可排序列并在列头显示相应箭头,还可拖动行
   13:同 12。
   14:除 12 功能外,可拖动列
   15:同 14。
方法二:
Private Sub VSG1_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
   Dim r%, c%
   r = VSG1.MouseRow
   c = VSG1.MouseCol
   If r = 0 And c > 0 Then
       VSG1.Tag = c
       VSG1.Cell(flexcpBackColor, 0, c) = vbYellow
       VSG1.MousePointer = flexPointerMove
   End If
End Sub
Private Sub VSG1_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
   If Len(VSG1.Tag) Then
       Dim r%, c%, p%
       r = VSG1.MouseRow
       c = VSG1.MouseCol
       If r = 0 And c > 0 Then p = flexPointerMove
       If VSG1.MousePointer <> p Then VSG1.MousePointer = p
   End If
End Sub
Private Sub VSG1_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)
   If Len(VSG1.Tag) Then
       Dim r%, c%, target%
       target = VSG1.Tag
       VSG1.Cell(flexcpBackColor, 0, target) = 0
       VSG1.Tag = ""
       VSG1.MousePointer = 0
       r = VSG1.MouseRow
       c = VSG1.MouseCol
       If r = 0 And c > 0 And c <> target Then
           VSG1.ColPosition(target) = c
       End If
   End If
End Sub
━━━━━━━━━━
VSFlexString控件属性一览表
CaseSensitive         ???
Error                 失败时取得错误信息
Index                 索引
MatchCount            取得与检索条件相一致的字符串数量
MatchIndex            设定与检索条件相一致的字符串的索引
MatchLength           取得与检索条件相一致的字符串长度
MatchStart            取得与检索条件相一致的字符串起始位置
MatchString           取得与检索条件相一致的字符串
Name
Object
Parent
Pattern               设定检索条件
Replace               设定置换字符串
Soundex               取得代表当前检索字符的声音代码
Tag
TagCount              取得与检索条件相一致的标签数量
TagIndex              在多个标签情况下,设定/取得与检索条件相一致的标签索引
TagLength             取得与检索条件相一致的标签长度
TagStart              取得与检索条件相一致的标签起始位置
TagString             取得与检索条件相一致的标签的字符串
Text                  设定成为检索对象
Version               取得FlexString的版本号
MSFlexGrid与VSFlexGrid的单元格合并例子:
Private Sub Form_Load()
Dim i As Long
With fg
   .WordWrap = True
   .Rows = 6
   .Cols = 6
   .FixedRows = 2
   .FixedCols = 0
   .ColWidth(0) = 1500
   .RowHeight(0) = 300
   .RowHeight(1) = 300
   .TextMatrix(1, 1) = "进货"
   .TextMatrix(1, 2) = "销售"
   .TextMatrix(1, 3) = "退货"
   .TextMatrix(1, 4) = "结存"
 
   For i = 1 To .Rows - 1
     .RowHeight(i) = 300   '设置行高
   Next i
   For i = 0 To 1
    .TextMatrix(i, 0) = "上月" & vbCrLf & "结存数量"          '//换行
    .FixedAlignment(0) = 4
   Next i
   For i = 0 To 1
    .TextMatrix(i, 5) = "月末结存"
    .FixedAlignment(5) = 4
   Next i
   For i = 1 To 4
     .TextMatrix(0, i) = "本月进销存数量"
     .ColAlignment(i) = 4
   Next i
 
   .MergeCells = flexMergeFree
'   .MergeCells = flexMergeFixedOnly
   .MergeCol(0) = True
   .MergeRow(0) = True
   .MergeCol(5) = True
End With
End Sub
请问:如何使用 VSFlexGrid Pro 分级显示和存取数据库中的数据。类似于《让 TreeView 支持无限级分类》帖子中所介绍的使用树形控件显示和存取数据库的数据。
Dim cn as New ADODB.Recordset
Dim rs As New ADODB.Recordset
Dim lngY As Long
Dim intT As Integer
cn.open "............"
rs.Open "select 系统编号 from test order by 系统编号", cn
With VSFlexGrid1
     Set .DataSource = rs
         .RowOutlineLevel(1) = 1
         .IsSubtotal(1) = True
   
     For lngY = 1 To .Rows - 1
         intT = Len(.TextMatrix(lngY, 0)) - Len(Replace(.TextMatrix(lngY, 0), ".", ""))
         .RowOutlineLevel(lngY) = intT
         .IsSubtotal(lngY) = True
     Next
     .OutlineCol = 0
     .OutlineBar = flexOutlineBarSimpleLeaf
   
End With
 
Set VSFlexGrid1.DataSource = Rs'这一步一定要有,
With VSFlexGrid1
            .DataRefresh
           
            .Sort = flexSortGenericDescending'排序
        
End With
例如:显示有小数点后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
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值