VSFlexGrid的用法--VB6 联系客服

发布时间 : 星期二 文章VSFlexGrid的用法--VB6更新完毕开始阅读d3307edcb9f3f90f76c61b3c

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 = \Adodc1.LockType = adLockBatchOptimistic Adodc1.RecordSource = \ablename\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(\ 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 =\加上“'”号则可以

解决上面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 '固定几列 .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 = \选定单元字符 .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