VSFlexgrid、MSFlexGrid控件的技术问题222

来源:百度文库 编辑:神马文学网 时间:2024/04/30 06:35:00
论坛公告: 友情提醒
黑马软件站首页 | 编程技巧 | 下载中心 | 界面设计 | 商业源码 | 问题反馈 收藏本页 联系我们 论坛帮助 恢复默认设置登录 |注册 |搜索 |风格 |论坛状态 |论坛展区 |黑马软件首页 |黑马博客 |我能做什么 
黑马软件论坛 → Visual Basic编程中心 → 控件天地 → VSFlexgrid、MSFlexGrid控件的技术问题
#TopicAppraise{font-size:12px;line-height:18px;padding:0;background:#FFFFE6;border:2px solid #222;text-align:left;z-index: 98;display: none;position: absolute;}
帖子评论 选取类型: 中立 支持 反对 观点标题: 验证码: 观点内容:
(不支持HTML)
  1. 请以客观、真实地作出评论,并注意语言文明;
  2. 观点发表后不能作出更改;
您是本帖的第 26682 个阅读者树形 打印 标题: VSFlexgrid、MSFlexGrid控件的技术问题流星 等级:超级版主文章:1236积分:11686注册:2005年12月17日楼主小 大  个性首页 | QQ | 邮箱 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舍五入)

 

例如:显示有小数点后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  '可调行和列


最近很多朋友问我关于VSflexgrid的问题,,,由于我很忙,没能及时回答,请多谅解;
特此,我找来了一些资料,供大家参考:

VSFLEXgrid控件概况】

[主要特点]
VSFlexGrid Pro 7.0 是一功能强大的数据表格控件,高速、紧凑、灵活、轻便、无须依赖任何应用工具,支持数据化格式选项,能将表格列连接到图象列和墙纸属性上以提高应用工具的实现程度。如果应用工具无须数据库的支持,如果你的应用程序不需要数据库的支持,那么使用VSFlexGrid Pro新的非绑定版本可以使应用程序的尺寸最小,而且发布应用程序时也不需要发布相应的ADO动态链接库. VSFlexGrid Pro 7.0可代替任何简单的列表框,浏览器,记事本等等,所以说它不仅仅只是一个表格控件。

FLexArray网格扩展控件
能够设置每个单元格的颜色和字体/能够对单元内容能进行快速有效的排序/设置RowPosition和ColPosition属性,即可在运行状态移动行列的位置/使用MergeCell属性,无须改写代码即可将内容一致的单元格加以合并/能够在设计过程定义行列的页眉、宽度和位置,进行界面设计/改变缺省字体大小,能够自动调整与之相对应的单元格尺寸/支持2000行以上表格,单元格内容可达32k以上/能够进行行列的隐藏/能够进行字体的微调整(参考FontWidth属性)/具有多种多样的网格形式和色彩/支持图文混排/多种光标和被选择内容的显示方式等等。

FlexString字符串处理控件
能够设定检索字符串与置换字符串, 在表格中找到与检索字符串相符的字符并将其置换为置换字符串中设置的字符/可以将检索字符串分成几个字段,给每个字段加入标签,使用标签代替字符串进行检索与置换/使用规范化表达式,规范化表达式是一个设定和匹配字符串的注释,类似于数学公式里的运算符。

[功能]
最新功能  
提供了丰富的功能可以迅速创建灵活、功能强大的前端,无须用户额外支出。VSFlexGrid Pro 7.0 100%向下兼容VB环境下的MSFlexGrid,所以对于目前的版本升级非常容易。

提供的新功能可显示、模块编辑、格式化、组织、概括、打印表格数据。数据可以按条件初始化,对于超出指定范围的数据会加强表示。可用户化输入网格和单个单元外观几乎所有的方面,并利用相似值合并邻近单元,使得表格更容易读取分析。

支持ADO和OLE DB

VSFlexGrid Pro支持ADO和OLE DB,支持统一的字符编码以及DAO数据的 存取,提供多重数据连接的选择。 ADO/OLEDB、DAO可连接到二维、三维 数组或其他VSFlexGrid控件,用户也可创建用户自己的数据源类。甚至可以 在无界模式中使用表格,或将表格连接到变量数组及一用户可自己开发的数据 源。

完整的打印功能
可以保存、检索多张表格和打印格式。最新的PrintGrid方法可让用户打印单 条语句,能够控制纸张定位、页边、文本字体,显示一对话框让用户选择设 置打印机。同时也可控制页中断,添加表头,并在每一页上添加用户单元。

支持分层数据
可进行排序, 模块编辑,转化组合框和图表框和自动数据聚合。甚至可使用 VSFlexGrid Pro 分级显示数据。类似于树形控件,通过显示删除或扩张的结点 用来表示含有附加数据的分支。分级显示树可在任一列中出现,甚至可出现 在异步分支上。分级显示树的外观可用NodeOpenPicture 和NodeClosedPicture 的属性用户化。

更简单的版本
如果用户的应用工具无须数据库的支持,VSFlexGrid Pro包含了表格控件更简 单的版本。使用VSFlexGrid Pro新的非绑定版本可以使应用程序的尺寸最小, 发布应用程序时也不需要发布相应的ADO动态链接库.消除了DLL版本的问题。

  
其他功能
合并单元
VSFlexGrid控件允许跨越多重行与列合并值相同的邻近单元。提高了数据在表 格中显示,提高了数据的读取和分析。单元合并可用于创建合并的图表表头、 合并的数据视图,以及创建能将文本溢出到相邻列的表格。

屏蔽模块
输入模板可说明自动控件以及有效数据的输入,减少了数据输入的错误。模块 语法类似于Microsoft MaskedEdit 控件和 Microsoft Access中的模块语法。
Component One Vs-Flex Grid pro 7.0

VB标准网络控件和文本控件的扩展
版本:7.0
标准价格:41,300.00 元
使用权限:发布免费


近期推出Videosoft公司一款全新的ActiveX控件---VSFlexGridPro7.0。 VSFlexGrid Pro 7.0 是一功能强大 的数据表格控件,高速、紧凑、灵活、轻便、无须依赖任何应用工具,支持数据化格式选项,能将表格列连接到图象列和墙纸属性上以提高应用工具的实现程度。如果应用工具无须数据库的支持,如果你的应用程序不需要数据库的支持,那么使用VSFlexGrid Pro新的非绑定版本可以使应用程序的尺寸最小,而且发布应用程序时也不需要发布相应的ADO动态链接库. VSFlexGrid Pro 7.0可代替任何简单的列表框,浏览器,记事本等等,所以说它不仅仅只是一个表格控件。


[主要特点]
FLexArray网格扩展控件
能够设置每个单元格的颜色和字体/能够对单元内容能进行快速有效的排序/设置RowPosition和ColPosition属性,即可在运行状态移动行列的位置/使用MergeCell属性,无须改写代码即可将内容一致的单元格加以合并/能够在设计过程定义行列的页眉、宽度和位置,进行界面设计/改变缺省字体大小,能够自动调整与之相对应的单元格尺寸/支持2000行以上表格,单元格内容可达32k以上/能够进行行列的隐藏/能够进行字体的微调整(参考FontWidth属性)/具有多种多样的网格形式和色彩/支持图文混排/多种光标和被选择内容的显示方式等等
FlexString字符串处理控件
能够设定检索字符串与置换字符串, 在表格中找到与检索字符串相符的字符并将其置换为置换字符串中设置的字符/可以将检索字符串分成几个字段,给每个字段加入标签,使用标签代替字符串进行检索与置换/使用规范化表达式,规范化表达式是一个设定和匹配字符串的注释,类似于数学公式里的运算符。

 

[新特性]
最新功能
提供了丰富的功能可以迅速创建灵活、功能强大的前端,无须用户额外支出。VSFlexGrid Pro 7.0 100%向下兼容VB环境下的MSFlexGrid,所以对于目前的版本升级非常容易。

提供的新功能可显示、模块编辑、格式化、组织、概括、打印表格数据。数据可以按条件初始化,对于超出指定范围的数据会加强表示。可用户化输入网格和单个单元外观几乎所有的方面,并利用相似值合并邻近单元,使得表格更容易读取分析。

支持ADO和OLE DB

VSFlexGrid Pro支持ADO和OLE DB,支持统一的字符编码以及DAO数据的 存取,提供多重数据连接的选择。 ADO/OLEDB、DAO可连接到二维、三维 数组或其他VSFlexGrid控件,用户也可创建用户自己的数据源类。甚至可以 在无界模式中使用表格,或将表格连接到变量数组及一用户可自己开发的数据 源。

完整的打印功能
可以保存、检索多张表格和打印格式。最新的PrintGrid方法可让用户打印单 条语句,能够控制纸张定位、页边、文本字体,显示一对话框让用户选择设 置打印机。同时也可控制页中断,添加表头,并在每一页上添加用户单元。

支持分层数据
可进行排序, 模块编辑,转化组合框和图表框和自动数据聚合。甚至可使用 VSFlexGrid Pro 分级显示数据。类似于树形控件,通过显示删除或扩张的结点 用来表示含有附加数据的分支。分级显示树可在任一列中出现,甚至可出现 在异步分支上。分级显示树的外观可用NodeOpenPicture 和NodeClosedPicture 的属性用户化。

更简单的版本
如果用户的应用工具无须数据库的支持,VSFlexGrid Pro包含了表格控件更简 单的版本。使用VSFlexGrid Pro新的非绑定版本可以使应用程序的尺寸最小, 发布应用程序时也不需要发布相应的ADO动态链接库.消除了DLL版本的问题。

其他功能
合并单元
VSFlexGrid控件允许跨越多重行与列合并值相同的邻近单元。提高了数据在表 格中显示,提高了数据的读取和分析。单元合并可用于创建合并的图表表头、 合并的数据视图,以及创建能将文本溢出到相邻列的表格。

屏蔽模块
输入模板可说明自动控件以及有效数据的输入,减少了数据输入的错误。模块 语法类似于Microsoft MaskedEdit 控件和 Microsoft Access中的模块语法

 

[控件属性一览表]
FlexString控件属性一览表
Error失败时取得错误信息
MatchCount取得与检索条件相一致的字符串数量
MatchIndex设定与检索条件相一致的字符串的索引
MatchLength取得与检索条件相一致的字符串长度
MatchStart
取得与检索条件相一致的字符串起始位置
MatchString取得与检索条件相一致的字符串
Pattern 设定检索条件
Replace设定置换字符串
SoundexText取得代表当前检索字符的声音代码
TagCount取得与检索条件相一致的标签数量
TagIndex在多个标签情况下,设定/取得与检索条件相一致的标签索引
TagLength取得与检索条件相一致的标签长度
TagStart取得与检索条件相一致的标签起始位置
TagString取得与检索条件相一致的标签的字符串
Text设定成为检索对象
Version取得FlexString的版本号


FlexString控件属性一览表
AllowBigSelection设定行列头的选择
AllowUserResizing设定行列大小的设定
BackColor设定FlexArray所有表格的背景颜色
BackColorBkg设定背景颜色
BackColorFixed设定固定行/列的背景颜色
BackColorSel设定选择单元的背景颜色
CellAlignment设定单元里数据的排列方式
CellBackColor设定单元或指定范围的背景颜色
CellFontBold把单元或指定范围的字体设定为黑体字
CellFontItalic把单元或指定范围的字体设定为斜体字
CellFontName设定单元或指定范围的字体
CellFontSize设定单元或指定范围字体的大小
CellFontWidth设定单元或指定范围字体的宽度
CellForeColor设定单元或指定范围字体的颜色
CellHeight返回当前单元的高度
CellLeft返回当前单元的左端位置
CellTop返回当前单元的顶端位置
CellWidth返回当前单元的宽度
CellPicture指定显示在单元或指定范围中的图片
CellPicture
Alingment指定单元或范围中图片的显示位置
CellTextStyle设定单元文本的显示形式
Clip<设定/返回选择范围的内容
Col设定/返回激活单元的列号
ColAlingment( )设定/返回列的排列方式
ColData( )设定/返回一个用户定义信息的长整形数据
ColPosition( )移动列的位置
Cols指定返回列的总数
ColSel指定选择范
ColWidth( )设定所指定列的宽度
FillStyle指定是否改变当前单元或选择范围的内容或单元格式
FixedCols设定固定列的总数
FixedRows设定固定行的总数
FocusRect设定选中单元周围的Focus Rectangle类型
FontWidth设定字体的宽度
ForeColorFixed设定固定单元的文本颜色
ForeColorSel设定选择单元的文本颜色
FormatString在设计过程中设定列宽、排列方式及固定的行/列
GridColor指定网格线的颜色
GridColorFixed设定固定网格线的颜色
GridLines指定网格线的类型
GridLinesFixed指定固定单元的网格线形式
HighLight设定是否突出显示选中单元
LeftCol指定显示在最左边的列
MergeCells设定是否合并内容相同的单元格
MergeCol( )设定指定列的单元合并
MergeRow( )设定指定行的单元合并
MouseCol设定鼠标指向的列号
MouseRow设定鼠标指向的行号
ReDraw设定是否刷新FlexArray控件
Picture返回FlexArray控件的图片
PictureType指定用Picture属性生成的图片类型
Row设定/返回激活单元的行号
RowData( )设定/返回一个用户定义信息的长整形数据
RowHeight( )设定指定行的高度
RowHeightMin设定行高的最小值
RowPosition( )移动行的位置
Rows指定行的总数
RowSel指定行的选择范围
SelectionMode设定行、列或单元的选择方式
ScrollBars设定卷动轴的类型
ScrollTrack设定卷动方式
Sort按照选择的基准重新排列行的顺序
Text设定/取得单元的文本
TextArray( )设定/取得任意单元的文本
TextMatrix( )设定/取得任意单元的文本
TextStyle显示单元中文本的3D效果
TextStyleFixed显示固定行/列中文本的3D效果
TopRow指定显示在最上面的行
Version
FlexArray控件的版本号
WordWrap设定单元中的文本是否换行


VSflexgrid的破解方法
注册方法:编辑注册表
HKEY_CLASSES_ROOT\Licenses\403E0785-49A9-11d3-9BD5-D2DC2DD96072


听过vsview7.0没有?这是破解方法,只需要在注册表里建立三个键就可以.如下:
REGEDIT4
VSVIEW 7
[HKEY_CLASSES_ROOT\Licenses\04589820-F8F4-11d3-9A1F-AE842F4A083B]
@=""
[HKEY_CLASSES_ROOT\Licenses\F403E0785-49A9-11d3-9BD5-D2DC2DD96072]
@=""
[HKEY_CLASSES_ROOT\Licenses\403E0785-49A9-11d3-9BD5-D2DC2DD96072]
@=""

在vsflexgrid中单元格输入完毕后,设置按回车键跳到同一行的下一个单元

Private Sub VSFlexGrid1_AfterEdit(ByVal Row As Long, ByVal Col As Long)
    With VSFlexGrid1
        If .Col = .Cols - 1 Then
            '如果到了最右边的列就跳到下一行第一个可非固定列
            .Row = Row + 1
            .Col = .FixedCols
        Else
            '向右移动一列
            .Col = Col + 1
        End If
    End With
End Sub

vsflexGrid 如何只能让某些特定列可编辑

'修改前看到是否需要修改
Private Sub Grid_BeforeEdit(ByVal Row As Long, ByVal Col As Long, Cancel As Boolean)
'On Error GoTo err

    If UiI10101.valueInt > 2 Then           '*************定义允许修改的状态,需修改
        Cancel = True
        Exit Sub
    End If
    If Grid.Col = Grid.cols - 8 Or Grid.Col = Grid.cols - 7 Then        '*************定义可以修改的列,需修改
        Cancel = False      '使其有效
    Else
        Cancel = True       '使其无效为真
    End If
    Exit Sub
Err:
    RaiseErr "frmY005-Grid_MouseDown()"
End Sub


'修改后判断是否合法
'cancel=true 取消修改的
Private Sub Grid_ValidateEdit(ByVal Row As Long, ByVal Col As Long, Cancel As Boolean)
On Error Resume Next
    If Not IsNumeric(Grid.EditText) Then
        MsgBox "输入不合法,应输入一个数值", vbInformation, "提示"
        Cancel = True
        Exit Sub
     End If
  
End Sub

'修改后来更改别的一些数据
Private Sub Grid_AfterEdit(ByVal Row As Long, ByVal Col As Long)
On Error Resume Next
'进货数量=包装数量 * 整装数量 + 零装数量
    Grid.TextMatrix(Row, Grid.cols - 6) = Grid.TextMatrix(Row, Grid.cols - 9) * Grid.TextMatrix(Row, Grid.cols - 8) + Grid.TextMatrix(Row, Grid.cols - 7)

End Sub


VSFLEXGRID7 中文输入法自动关闭问题提示

同种数据类型的单元格之间变换不要重启输入法.....
还有可以看看这代码
Private Declare Function GetKeyboardLayoutList Lib "user32" (ByVal nBuff As Long, _
        lpList As Long) As Long
Private Declare Function GetKeyboardLayoutName Lib "user32" Alias "GetKeyboardLayoutNameA" _
        (ByVal pwszKLID As String) As Long
Private Declare Function GetKeyboardLayout Lib "user32" (ByVal dwLayout As Long) As Long
Private Declare Function ImmGetDescription Lib "imm32.dll" Alias "ImmGetDescriptionA" (ByVal _
        hkl As Long, ByVal lpsz As String, ByVal uBufLen As Long) As Long
Private Declare Function ActivateKeyboardLayout Lib "user32" (ByVal hkl As Long, ByVal _
        flags As Long) As Long
        
Const IME_CONFIG_GENERAL = 1
Const KLF_REORDER = &H8
Const KLF_ACTIVATE = &H1

Dim la(1 To 16) As Long           '输入法列表
Dim ActIme As Long                '当前输入法
Dim X%                            '当单前输入法数量

Private Sub Form_Load()
   X = GetKeyboardLayoutList(32, la(1))
end sub

Private Sub vs1_AfterEdit(ByVal Row As Long, ByVal Col As long)     'vsflexgrid 控件存在输入问题? 以下为避免方法
Dim colNumber As Long
Dim i As Long
Dim strName$
if col=1 then
  ActivateKeyboardLayout la(1), 1
else
  ActivateKeyboardLayout la(2), 2
end if
end Sub

用.AddItem在最后一行显示数据
Rst_Hj.Open HjSQL, Cnn_Zl, adOpenDynamic, adLockOptimistic    'RST_hj是合计的记录集
Main_YX.VSFlexGrid1.AddItem vbTab & vbTab & vbTab & vbTab & vbTab & vbTab & vbTab & vbTab & vbTab & vbTab & "合计" & vbTab & Rst_Hj.Fields(0) & vbTab & Rst_Hj.Fields(1) & vbTab & Rst_Hj.Fields(2) & vbTab & Rst_Hj.Fields(3)      'VBTAB是跳过一格填写
Rst_Hj.Close

'删除连续选择的记录
If VSFlexGrid1.Row <> -1 And VSFlexGrid1.RowSel <> -1 Then
   msg = MsgBox("你真的要删除这些记录吗?", vbYesNo + vbQuestion)
   Select Case msg
    Case vbYes
      For I = VSFlexGrid1.Row To VSFlexGrid1.RowSel
        Str = Str + VSFlexGrid1.TextMatrix(I, 1) + ","
      Next
      Str = Mid(Str, 1, Len(Str) - 1)
      Cmd_Zl.ActiveConnection = Cnn_Zl
      Cmd_Zl.CommandText = "delete from zlk where 序号 in (" + Str + ")"
      Cmd_Zl.Execute
      Set Cmd_Zl = Nothing
    Case vbNo
       Command6.Enabled = True
       Rst_Zl.Close
       Exit Sub
    End Select
Else
    MsgBox "请选择您要删除的记录!!!", vbExclamation
    Exit Sub
End If
这是用vsprinter打印vsflexgrid内容的例子,你可做参考。页面设置的功能我也正在查找,如果找到肯定共享。
With VSPrinter1
        '设置表头,创建打印文档
        .Header = "|" & strTitle & vbCrLf & "|Page %d " '显示Page n功能
        
        .StartDoc
        .Zoom = 100'显示比例
        .RenderControl = vsFlexGrid1.Hwnd'把网格内容传递给vsView显示
        .EndDoc
    End With

有谁知道vsflexgrid1.PrintGrid命令参数怎么用?附上原英文帮助,有谁看懂了请解释一下好吗!
Prints the grid on the printer.
Syntax    
[form!]VSFlexGrid.PrintGrid [ DocName As String ], [ ShowDialog As Boolean ], [ Orientation As Integer ], [ MarginLR As Long ], [ MarginTB As Long ]
Remarks    
The parameters for the PrintGrid method are described below:


DocName As String  (optional)
Contains the name of the document being printed. This string appears in the printer window's job list and is also used as a footer.

ShowDialog As Variant  (optional, default value = False)
If set to True, a printer selection/setup dialog is displayed before the document start printing. The user can then select which printer to use, page orientation etc.

Orientation As Variant  (optional, default value = printer default)
Set this parameter to 1 to print the grid in Portrait mode, or set it to 2 to print the grid in Landscape mode. The default setting, zero, uses the default printer orientation.

MarginLR As Variant  (optional, default value = 1440)
Left and right margins, in twips. The margins must be equal. The default value, 1440, corresponds to a one-inch margin.

MarginTB As Variant  (optional)
Top and bottom margins, in twips. The margins must be equal. The default value, 1440, corresponds to a one-inch margin.


The grid is printed using the same fonts used to display it on the screen, so to achieve best results, make sure the grid's Font property is set to a TrueType font (such as Arial, Times New Roman, Tahoma, or Verdana).

While printing the grid, the control fires the BeforePageBreak and GetHeaderRow events. These events allow you to control page breaks and setup repeating headers.

The PrintGrid method prints the entire grid, possibly spilling across and down to new pages. To print only a part of the grid, hide to rows and columns you don't want to print, call the PrintGrid method, and restore the hidden rows and columns when you are done.

The code below shows how you can do this:

    Private Sub PrintSelection(fg As VSFlexGrid, Row1&, Col1&, Row2&, Col2&)
    
        ' save current settings
        Dim hl%, tr&, lc&, rd%
        hl = fg.HighLight: tr = fg.TopRow: lc = fg.LeftCol: rd = fg.Redraw
        fg.HighLight = 0
        fg.Redraw = flexRDNone
    
        ' hide non-selected rows and columns
        Dim i&
        For i = fg.FixedRows To fg.Rows - 1
            If i < Row1 Or i > Row2 Then fg.RowHidden(i) = True
        Next
        For i = fg.FixedCols To fg.Cols - 1
            If i < Col1 Or i > Col2 Then fg.ColHidden(i) = True
        Next
    
        ' scroll to top left corner
        fg.TopRow = fg.FixedRows
        fg.LeftCol = fg.FixedCols
    
        ' print visible area
        fg.PrintGrid
    
        ' restore control
        fg.RowHidden(-1) = False
        fg.ColHidden(-1) = False
        fg.TopRow = tr: fg.LeftCol = lc: fg.HighLight = hl
        fg.Redraw = rd
    End Sub

960521,提供的“如何设置vsflexgrid某行背景色”:

    VSFlexGrid1.Cell(flexcpBackColor, row1, col1,row2, col2) = vbRed

例:设置第三行北景色为红
    VSFlexGrid1.Cell(flexcpBackColor, 3, 1, 3, VSFlexGrid1.Cols - 1) = vbRed

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 







您的进步,我的动力,让我们一起提高!
  • 评论[支持者: 0 人反对者: 0 人中立者: 0 人] 查看评论信息
2006-3-3 15:58:08 本站推荐:黑马按钮控件流星 等级:超级版主文章:1236积分:11686注册:2005年12月17日第 2 楼小 大  个性首页 | QQ | 邮箱 当 MergeCells 被设置为除 0 (不显示)以外的一个值时,突出显示的选择自动关闭。这样做是为加速重画,也是因为包含合并单元范围的选择可能导致不可预料的结果。

**********************************

MergeCol、MergeRow 属性

返回或设置一个值,决定哪些行和列可以把它们的内容合并。要使用 MergeCells 属性,这些属性必须为 True。

语法

object.MergeCol(number) [=Boolean]
object.MergeRow(number) [=Boolean]

MergeCol 和 MergeRows 属性的语法包含如下部分:

部分 描述
Object 一个对象表达式,其值为“应用于”列表中的一个对象。
number 一个 Long值,指定 MSHFlexGrid 中的列或行。
Boolean 一个 Boolean值,指定当相邻单元显示相同内容时合并是否发生。


设置值

Boolean 的设置值如下所示:

部分 描述
True 当相邻单元显示相同内容时,行向左合并或列向上合并。
False 当相邻单元显示相同内容时,单元不合并。这是 MergeCol 和 MergeRow 缺省设置值。


说明

如果 MergeCells 属性被设置为非零值,具有相同值的相邻单元,只有它们都在一行并且 MergeRow 属性被设置为 True,或都在一列且 MergeCol 属性被设置为 True 时才合并。

***********************************************************

例子:

不合并
MergeCells =0
MergeRow(0) =True
MergeRow(1) =True
MergeRow(2) =True
MergeRow(3) =False
这是标准视图。

自由合并
MergeCells =1
MergeRow(0) =True
MergeRow(1) =True
MergeRow(2) =True
MergeRow(3) =False
注意第三个 employee 单元 (Donna) 如何合并它左边的 products 和它右边的 sales。

限制合并
MergeCells =2
MergeRow(0) =True
MergeRow(1) =True
MergeRow(2) =True
MergeRow(3) =False
注意第三个 employee 单元 (Donna) 不再合并 sales。



  • 评论[支持者: 0 人反对者: 0 人中立者: 0 人] 查看评论信息
2006-3-4 8:47:31 您的进步,我的动力,欢迎光临黑马编程论坛。流星 等级:超级版主文章:1236积分:11686注册:2005年12月17日第 3 楼小 大  个性首页 | QQ | 邮箱 用VSFlexGrid做的目录树遍历,就像TreeView!
Sub DirTree(fdRoot As Folder, outText As String)

Dim fd As Folder, subFds As Folders
' Dim Fi As file, Fis As Files
Set subFds = fdRoot.SubFolders

mLevel = mLevel + 1

For Each fd In subFds

fg.AddItem fd.Name & vbTab & Format$(ByteToKB(fd.Size), "#,###")

fg.IsSubtotal(fg.Rows - 1) = True
fg.RowOutlineLevel(fg.Rows - 1) = mLevel - 1

'遍历文件(如果有需要)
' Set Fis = fd.Files
' For Each Fi In Fis
' outText = outText & String(mLevel * 2, " ") & " " & Fi.Name & vbCrLf
' Next

If fd.SubFolders.Count Then

DirTree fd, outText

End If

Next

mLevel = mLevel - 1

End Sub



  • 评论[支持者: 0 人反对者: 0 人中立者: 0 人] 查看评论信息
2006-3-4 8:47:47 本站推荐:黑马按钮控件流星 等级:超级版主文章:1236积分:11686注册:2005年12月17日第 4 楼小 大  个性首页 | QQ | 邮箱 您无权查看精华贴子
  • 本贴被加为精华
  • 评论[支持者: 0 人反对者: 0 人中立者: 0 人] 查看评论信息
2006-3-4 8:48:59 本站推荐:黑马按钮控件流星 等级:超级版主文章:1236积分:11686注册:2005年12月17日第 5 楼小 大  个性首页 | QQ | 邮箱

Private Sub fillup_Click() '向上填充
Dim i As Integer
Dim j As Long
Dim k As Long
Dim m As Long
Dim n As Long
VF.GetSelection j, k, m, n
For i = j To m ' VF.RowSel
VF.TextMatrix(i, VF.Col) = VF.Text
Next i

End Sub



  • 评论[支持者: 0 人反对者: 0 人中立者: 0 人] 查看评论信息
2006-11-27 23:01:03 挑战自己,共同提高,欢迎参予VB问题大赛charevin 等级:编程爱好者文章:1积分:65注册:2007年5月27日第 6 楼小 大  个性首页 | 邮箱 看看

 

vsflexgrid技巧大全 如何实现将vsflexgrid中修改的数据反馈到数据库中??
Private Sub vsflexgrid1_AfterEdit(ByVal Row As Long, ByVal Col As Long)
   rs.MoveFirst     '//rs为记录集
   rs.Move vsflexgrid1.Row - 1
   rs.Edit
   If vsflexgrid1.text = "" Then
       rs.Fields(vsflexgrid1.Col - 1) = Null
   Else
      rs.Fields(vsflexgrid1.Col - 1) = vsflexgrid1.text
   End If
   rs.Update
end sub

  
一、增加记录使用for来循环表格行。
     for i=1 to grid1.rows-1
           with rs
                  .addnew
                  .fileds(o)=grid1.textmariy(i,0)
                  .fileds(1)=grid1.textmariy(i,1)
                  .fileds(2)=grid1.textmariy(i,2)
                  .fileds(3)=grid1.textmariy(i,3)
                  .update
            end with
       next
二、添加行
  grid1.additem row
三、删除当前行
  with grid1
             i=.row
             .removeitem i
       end with
四、要显示下拉框,可以使用vsflexgrid中列绑定功能
  grid1.colcombolist(1)=grid.buildcombolist(rs,"商品名称")
跟楼上的相比,仅仅是datamode不一样(2-flexDMBoundBatch)
但这样做的优势是非常明显的:可以撤销包括新增删除在内的所有操作,按保存键才写入数据库
Private Sub CmdDel_Click()
If fg.Row <> 0 Then fg.RemoveItem (fg.Row)
fg.Refresh
End Sub
Private Sub CmdAdd_Click()
On Error Resume Next
Adodc1.Recordset.AddNew
If Err.Number <> 0 Then MsgBox Err.Description
End Sub
Private Sub CmdUpdate()
Adodc1.Recordset.UpdateBatch adAffectAllChapters
End Sub
Private Sub CmdCancel_Click()
     Adodc1.Recordset.CancelBatch
     fg.DataRefresh
End Sub

Private Sub Form_Load()
Adodc1.ConnectionString = "FILE NAME=" & App.Path & "\conn.dsn"
Adodc1.LockType = adLockBatchOptimistic
Adodc1.RecordSource = "Your_Tablename"
Set fg.DataSource = Adodc1
End Sub
  
1、打印vsflexgrid可以使用vsprinter打印控件。跟vsflexgrid配套使用效果不错。
2、导出EXECL,可以使用grid.savegrid的方法。
    用savegrid的方法 ,在导出execl时,如果碰到类似于银行帐号的列如:“6465456665”,导到EXECL中就不这样显示了,这个问题还不知道怎么解决??
    另外也可以写代码(这个方法比较实用,但慢一些):
    Dim excelApp As Excel.Application
     Set excelApp = New Excel.Application
     On Error Resume Next
     If excelApp Is Nothing Then
        Set excelApp = CreateObject("Excel.application")
        If excelApp Is Nothing Then
           Exit Sub
        End If
     End If
     excelApp.Visible = True
     Me.MousePointer = vbHourglass
     excelApp.Workbooks.Add
     With excelApp.ActiveSheet
         Dim i As Integer, j As Integer
         For i = 1 To Grid1.rows
             For j = 1 To Grid1.Cols
                   .Cells(i, j).value ="'"& Grid1.TextMatrix((i - 1), (j - 1))'加上“'”号则可以解决上面savegrid中银行帐号的导出问题。

 


  • 评论[支持者: 0 人反对者: 0 人中立者: 0 人] 查看评论信息
2007-5-27 19:15:44 挑战自己,共同提高,欢迎参予VB问题大赛wf12586 等级:编程爱好者文章:2积分:76注册:2007年6月6日第 7 楼小 大  个性首页 | 邮箱

如何实现将vsflexgrid中修改的数据反馈到数据库中

 

如何实现将vsflexgrid中修改的数据反馈到数据库中?
Private Sub vsflexgrid1_AfterEdit(ByVal Row As Long, ByVal Col As Long)
  rs.MoveFirst    '//rs为记录集
  rs.Move vsflexgrid1.Row - 1
  rs.Edit
  If vsflexgrid1.text = "" Then
      rs.Fields(vsflexgrid1.Col - 1) = Null
  Else
     rs.Fields(vsflexgrid1.Col - 1) = vsflexgrid1.text
  End If
  rs.Update
end sub 

  
一、增加记录使用for来循环表格行。 
    for i=1 to grid1.rows-1
          with rs
                 .addnew
                 .fileds(o)=grid1.textmariy(i,0)
                 .fileds(1)=grid1.textmariy(i,1)
                 .fileds(2)=grid1.textmariy(i,2)
                 .fileds(3)=grid1.textmariy(i,3)
                 .update
           end with
      next
二、添加行
  grid1.additem row
三、删除当前行
  with grid1
            i=.row
            .removeitem i
      end with
四、要显示下拉框,可以使用vsflexgrid中列绑定功能
  grid1.colcombolist(1)=grid.buildcombolist(rs,"商品名称") 
跟楼上的相比,仅仅是datamode不一样(2-flexDMBoundBatch)
但这样做的优势是非常明显的:可以撤销包括新增删除在内的所有操作,按保存键才写入数据库
       Private Sub CmdDel_Click()
             If  fg.Row <> 0 Then fg.RemoveItem (fg.Row)
                  fg.Refresh
        End Sub

 Private Sub CmdAdd_Click()
On Error Resume Next
Adodc1.Recordset.AddNew
If Err.Number <> 0 Then MsgBox Err.Deion
End Sub

Private Sub CmdUpdate()
Adodc1.Recordset.UpdateBatch adAffectAllChapters
End Sub

Private Sub CmdCancel_Click()
    Adodc1.Recordset.CancelBatch
    fg.DataRefresh
End Sub

Private Sub Form_Load()
Adodc1.ConnectionString = "FILE NAME=" & App.Path & "\conn.dsn"
Adodc1.LockType = adLockBatchOptimistic
Adodc1.RecordSource = "Your_Tablename"
Set fg.DataSource = Adodc1
End Sub
  
1、打印vsflexgrid可以使用vsprinter打印控件。跟vsflexgrid配套使用效果不错。
2、导出EXECL,可以使用grid.savegrid的方法。
   用savegrid的方法 ,在导出execl时,如果碰到类似于银行帐号的列如:“6465456665”,导到EXECL中就不这样显示了,这个问题还不知道怎么解决?? 
   另外也可以写代码(这个方法比较实用,但慢一些):
   Dim excelApp As Excel.Application
    Set excelApp = New Excel.Application
    On Error Resume Next
    If excelApp Is Nothing Then
       Set excelApp = CreateObject("Excel.application")
       If excelApp Is Nothing Then
          Exit Sub
       End If
    End If
    excelApp.Visible = True
    Me.MousePointer = vbHourglass
    excelApp.Workbooks.Add
    With excelApp.ActiveSheet
        Dim i As Integer, j As Integer
        For i = 1 To Grid1.rows
            For j = 1 To Grid1.Cols
                  .Cells(i, j).value ="'"& Grid1.TextMatrix((i - 1), (j - 1))'加上“'”号则可以解决上面savegrid中银行帐号的导出问题。 
            Next j
            DoEvents
        Next i
    End With
    Me.MousePointer = vbDefault
    Set excelApp = Nothing
End Sub
  EXCEL同Vsflexgrid通过
最近很多的朋友,都想知道EXCEL怎样同VSflexgrid交换数据。
实际上,利用“复制”、“粘贴”菜单即可实现。具体如下:
(1)在Vsflexgrid上弹出右键菜单
  Private Sub grid1_MouseDown(Button As Integer, Shift As Integer, X As Single, y   As Single)
    if  Button = 2 Then  PopupMenu mnutccd
  End Sub
(2)设置各菜单的内容
A 复制
    Clipboard.Clear
    Clipboard.SetText grid1.Clip
B 剪切
   Dim rowc As Long
   Dim rowz As Long
   Dim colc As Long
   dim colz As Long
   dim i as long 
   dim s as long
   If grid1.Rows = 1 Then Exit Sub
   Clipboard.Clear
  Clipboard.SetText grid1.Clip
   If grid1.RowSel > grid1.row Then
       rowc = grid1.row
       rowz = grid1.RowSel
   Else
       rowc = grid1.RowSel
      rowz = grid1.row
   End If
   If grid1.ColSel > grid1.Col Then
      colc = grid1.Col
      colz = grid1.ColSel
   Else
      colc = grid1.ColSel
      colz = grid1.Col
    End If
    For i = rowc To rowz
       For s = colc To colz
           grid1.TextMatrix(i, s) = ""
      Next
    Next
C 粘贴(精华部分)
  Dim i As Long
  Dim s As Long
  Dim m As Long
  Dim t As Long
   If grid1.Rows = 1 Then Exit Sub
   t = Len(Clipboard.GetText)
   If t = 0 Then Exit Sub
   For i = 1 To t
      If Mid(Clipboard.GetText, i, 1) = Chr(9) Then s = s + 1
      If Mid(Clipboard.GetText, i, 1) = Chr(13) Then m = m + 1
   Next
   If s / (m + 1) + grid1.Col > grid1.Cols - 1 Then
       grid1.ColSel = grid1.Cols - 1
   Else
      grid1.ColSel = s / (m + 1) + grid1.Col
   End If
   If grid1.row + m > grid1.Rows - 1 Then
       grid1.RowSel = grid1.Rows - 1
   Else
       grid1.RowSel = grid1.row + m
   End If
   grid1.Clip = Clipboard.GetText 


  
VSFlexGrid 常用属性或方法: 
.FixedRows = 1                            '固定几行
.FixedCols = 1                          &nbs

 

p; '固定几列
.Editable = True                          '允许修改
.AllowUserResizing = flexResizeBoth       '可调整行/列
.FocusRect = flexFocusNone                '无虚框
.SelectionMode = flexSelectionListBox     '焦点选中样式
.BackColor = RGB(255, 255, 255)           '单元背景色
.BackColorSel = vbBlue                    '单元选择色
.BackColorFixed = RGB(208, 192, 160)      '固定单元色
.BackColorAlternate = RGB(255, 250, 230)  '间隔行背景色
.GridColor = RGB(245, 240, 210)           '单元线条色
.ForeColor = RGB(0, 0, 0)                 '单元前景色(字符色)
.RowHeightMin = 260                       '最小行高
.RowHeightMax = 800                       '最大行高
.ColHeightMin = 50                        '最小列宽
.ColHeightMax = 3000                      '最大列宽
.ColWidth(Col) = 1000                     '指定列宽
.RowHeight(Row) = 260                     '指定行高
.TextMatrix(Row,Col) = "Text"             '指定单元字符
.Text = "Text"                            '选定单元字符
.MergeCol(Col) = True                     '允许合并列
.MergeRow(Row) = True                     '允许合并行
.MergeCells = 0|1|2|3|4|5|6               '合并选项
.Cell(选项准则, Row1, Col1, Row2, Col2)   '选择部分的相应准则值
.EditCell                                 '当移动到当前单元时自动选择
.EditSelStart                             '移动到单元时的光标位置
.MousePointer                             '设置对象的鼠标指针样式 O.A = 0 到 15|99
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
几个特殊的属性方法的使用:
FormatString 属性:管道符格式化字符串示例:
下面定义对齐方式同字意,列宽窄同距离
VSG1.FormatString = "^  中 |<     左    |>   右  |>   右  |^  中  "
+++++++++++++++++++++++++
搜索(查找)表格中符合条件的行:
FindRow 属性:该属性返回一个行值
MsgBox VSG1.FindRow(关键词,[指定行],[指定列],[敏感],[精度])
关键词:String,表示要搜索的字符串
指定行/指定列:Long,表示只在指定的行或列中找
敏感:Boolean,
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
'限制只能在指定列输入(这里默认倒数第2列)
Private Sub VSG1_BeforeRowColChange(ByVal OldRow As Long, _
       ByVal OldCol As Long, ByVal NewRow As Long, _
       ByVal NewCol As Long, Cancel As Boolean)
  VSG1.Editable = flexEDKbd
  If VSG1.Redraw <> flexRDNone And NewCol <> VSG1.Cols - 2 Then
     Cancel = True
     VSG1.Select NewRow, VSG1.Cols - 2
  End If
End Sub
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
限制不能编辑某些列:(这里限制第1列和第3列)
Private Sub VSG1_RowColChange()
   If VSG1.Col = 1 Or VSG1.Col = 3 Then
      VSG1.FocusRect = flexFocusNone
      VSG1.Editable = flexEDNone
     'SendKeys "{TAB}"
   Else
      VSG1.Editable = flexEDKbd
      SendKeys "{ENTER}"
   End If
End Sub
或:
Private Sub VSG1_RowColChange()
If VSG1.Col = 1 Or VSG1.Col = 3 Then
   SendKeys "{RIGHT}"
Else
   SendKeys "{ENTER}"
End If
End Sub
或:
Private Sub VSG1_RowColChange()
If VSG1.Col = 1 Or VSG1.Col = 3 Then
   VSG1.Editable = flexEDNone
Else
   VSG1.Editable = flexEDKbd
   VSG1.EditCell  '自动选择单元内容
   VSG1.EditSelStart = 0[选到最前]|1[选到指定]|Len(VSG1.Text)[选到最后]
End If
End Sub
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
'对齐方式(-1标示所有)
.ColAlignment(-1) = flexAlignLeftCenter|flexAlignCenterCenter|flexAlignRightCenter
示例1:(最后一行的第3列靠右对齐)
VSG1.Select VSG1.Rows - 1, 2
VSG1.CellAlignment = flexAlignRightCenter
示例2:
VSG1.Row = VSG1.Rows - 1: VSG1.Col = 1
VSG1.CellAlignment = flexAlignRightCenter
示例3:
VSG1.Cell(flexcpAlignment, VSG1.Rows - 1, 1, VSG1.Rows - 1, 3) = flexAlignRightCenter
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
本对象拖放:
Private Sub VSG1_MouseDown(Button As Integer, _
        Shift As Integer, X As Single, Y As Single)
VSG1.Drag
VSG1.DragIcon = LoadPicture("D:\Icon.ico")
VSG1.DragRow VSG1.RowSel
End Sub
或从其它对象拖:
Private Sub VSG2_MouseDown(Button As Integer, _
        Shift As Integer, X As Single, Y As Single)
VSG2.OLEDrag
VSG1.OLEDropMode = flexOLEDropAutomatic
End Sub
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
Public Sub VSGridCount(Optional SelRow As Long, Optional SelCol As Long)
Dim X As Long, i As Long
Dim Hj1, Hj2, Hj3 As String
Const A1 = -922337203685477#, A2 = 922337203685477#
On Error GoTo ErrTransact
With frmFG.VSG1
   X = .Rows - 1
   .MergeCells = flexMergeFree
   .MergeRow(X) = True
   .Cell(flexcpText, X, 0, X, 1) = "合 计"
   If .Rows = 3 Then
      .TextMatrix(X, 0) = 0
      .Cell(flexcpText, X, 2, X, 14) = " "
      .Cell(flexcpText, X, 16, X, 17) = "¥0.00"
      Exit Sub
   End If
   'Hj1 = Val(.Aggregate(flexSTSum, 2, 2, X - 1, 2))
   'Hj2 = Val(.Aggregate(flexSTSum, 2, 16, X - 1, 16))
   'Hj3 = CurrencyToStr(Hj2)
   For i = 2 To X - 2
       Hj1 = Hj1 + Val(.TextMatrix(i, 15))
       If Val(.TextMatrix(i, 16)) > 0 Then
          Hj2 = Hj2 + Val(.TextMatrix(i, 15)) * Val(.TextMatrix(i, 16))
       End If
   Next i
   If Hj2 <= A1 Or Hj2 >= A2 Then
     GoTo ErrTransact
   End If
   Hj3 = CurrencyToStr(Hj2)
   .TextMatrix(X,p;2) = Hj1
   .Cell(flexcpText, X, 3, X, 15) = IIf(Hj3 = "", " ", Hj3)
   .Cell(flexcpText, X, 16, X, 17) = Format(Hj2, "¥0.00")
   .Cell(flexcpAlignment, X, 2, X, 14) = flexAlignLeftCenter
   '.Select X, 3
   '.CellAlignment = flexAlignLeftCenter
   If SelRow > 1 And SelCol > 0 Then .Select SelRow, SelCol
End With
Exit Sub
ErrTransact:
     MsgBox "你输入的数字过大无法计算!请修改!!!"
End Sub
------------------------------------------------
将数字转换为大写金额的函数:
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 = x y
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


  • 评论[支持者: 0 人反对者: 0 人中立者: 0 人] 查看评论信息
2007-6-11 16:30:26 您的进步,我的动力,欢迎光临黑马编程论坛。DonBox 等级:编程爱好者文章:19积分:190注册:2007年7月28日第 8 楼小 大  个性首页 | 邮箱


fg.Cell(flexcpForeColor, Row, Col) = RGB(230, 0, 0)

VB中VSFLEXGRID 如何用鼠标点击某一行即选中该行,并且高亮显示

.SelectionMode = flexSelectionByRow

 

一、可以直接绑字,速度比较理想
1、建立数据的连接,比如是 con
2、建立recordset,比如是rs

用下面的方法

rs.open "本期库存,上期库存,收入,发出 from 库存表",cn
with  vsflexgrid
   set .recordsource=rs
   rs.close
end with

二、用additem方法实现
 with  vsflexgrid
   .additem "第一列"& vbtab & "第二列"
end with 

三、用.TextMatrix赋值
Private Sub Form_Load()
    Dim i As Integer
    Dim j As Integer

    With VSFlexGrid1
        For i = 0 To .Rows - 1

            For j = 0 To .Cols - 1
                .TextMatrix(i, j) = CStr(i) & "-" & CStr(j)

            Next

        Next

    End With
End Sub
''''''**********************

.EditSelStart=0
.EditSelLength=len(vsflexgrid.TextMatrix(row,col) 
''*****************

 

''''修改保存

Private Sub vsflexgrid1_AfterEdit(ByVal Row As Long, ByVal Col As Long)
  rs.MoveFirst    '//将记录集指针移动到第一条
  rs.Move vsflexgrid1.Row - 1 ‘再将指针移向用户选中行
  rs.Edit          ’记录集处理可编辑状态
  If vsflexgrid1.text = "" Then         ‘修改记录集
      rs.Fields(vsflexgrid1.Col - 1) = Null
  Else
     rs.Fields(vsflexgrid1.Col - 1) = vsflexgrid1.text
  End If
  rs.Update    ’更新
end sub

 

;******************

 

‘’‘跟鼠标滚动

Private Sub fg_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
    fg.Redraw = flexRDBuffered
    fg.SelectionMode = flexSelectionByRow
    fg.Row = fg.MouseRow
    fg.BackColorSel = &H88FFB5
End Sub

 

’‘**********

 

使用adodc控件做数据库连接,不能为只读recordset
vsflexgrid.datamode=2

'新增按钮
Private Sub addNew_click()
    Adodc1.Recordset.addNew
End Sub

'保存按钮
Private Sub saveNew_click()
    Adodc1.Recordset.UpdateBatch
End Sub


vsflexgrid.datamode

 

 



No Passion,No Ideal?
  • 评论[支持者: 0 人反对者: 0 人中立者: 0 人] 查看评论信息
2007-7-28 18:14:17 黑马学生管理系统lixiang 等级:编程爱好者文章:4积分:80注册:2007年8月29日第 9 楼小 大  个性首页 | 邮箱

学习了不少东西!

感谢分享经验!


  • 评论[支持者: 0 人反对者: 0 人中立者: 0 人] 查看评论信息
2007-8-29 17:08:11 黑马学生管理系统shahe23 等级:编程爱好者文章:6积分:90注册:2008年3月9日第 10 楼小 大  个性首页 | 邮箱

谢谢。

当我单击一个单元格时,如何改变这个单元格的背景色呢?

请给出调试后的代码。


  • 评论[支持者: 0 人反对者: 0 人中立者: 0 人] 查看评论信息
2008-3-9 20:05:41 本站推荐:黑马按钮控件
 1  2        15 | 10   1/2 页
发短信
购买论坛点券
我能做什么
我发表的主题
我参与的主题
基本资料修改
用户密码修改
联系资料修改
用户短信服务
编辑好友列表
用户收藏管理
个人文件管理 今日贴数图例
主题数图例
总帖数图例
在线图例
在线情况
用户组在线图例 文件集浏览
图片集浏览
Flash浏览
音乐集浏览
电影集浏览
贺卡发送 Copyright ©2000 - 2008 heimasoft.com