如何实现将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中银行帐号的导出问题。 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
[1] [2] [3] [4] [5] 下一页 没有相关教程
|