1、vsflexgrid 应用技巧大全 怎么实现将vsflexgrid中修改的数据反馈到数据库中?PrivateSubvsflexgrid1_AfterEdit(ByValRowAsLong,ByValColAsLong)rs.MoveFirst/rs为记录集rs.Movevsflexgrid1.Row-1rs.EditIfvsflexgrid1.text=Thenrs.Fields(vsflexgrid1.Col-1)=NullElsers.Fields(vsflexgrid1.Col-1)=vsflexgrid1.textEndIfrs.Updateendsub一、增加记录使用for来循环表格
2、行。fori=1togrid1.rows-1withrs.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).updateendwithnext二、添加行grid1.additemrow三、删除当前行withgrid1i=.row.removeitemiendwith四、要显示下拉框,能使用vsflexgrid中列绑定功能grid1.colcombolist(1)grid.buildco
3、mbolist(rs,商品名称)跟楼上的相比,仅仅是datamode不相同(2-flexDMBoundBatch)但这样做的优势是非常明显的:能撤销包括新增删除在内的所有操作,按保存键才写入数据库 PrivateSubCmdDel_Click() If fg.Row0Thenfg.RemoveItem(fg.Row) fg.Refresh EndSubPrivateSubCmdAdd_Click()OnErrorResumeNextAdodc1.Recordset.AddNewIfErr.Number0ThenMsgBoxErr.DescriptionEndSubPrivateSubCmdUp
4、date()Adodc1.Recordset.UpdateBatchadAffectAllChaptersEndSubPrivateSubCmdCancel_Click()Adodc1.Recordset.CancelBatchfg.DataRefreshEndSubPrivateSubForm_Load()Adodc1.ConnectionString=FILENAME=&App.Path&conn.dsnAdodc1.LockType=adLockBatchOptimisticAdodc1.RecordSource=Your_TablenameSetfg.DataSource=Adodc1
5、EndSub1、打印vsflexgrid能使用vsprinter打印控件。跟vsflexgrid配套使用效果不错。2、导出EXECL,能使用grid.savegrid的方法。用savegrid的方法,在导出execl时,如果碰到类似于银行帐号的列如:“”,导到中就不这样显示了,这个问题还不知道怎么解决?另外也能写代码(这个方法比较实用,但慢一些):DimexcelAppAsExcel.ApplicationSetexcelApp=NewExcel.ApplicationOnErrorResumeNextIfexcelAppIsNothingThenSetexcelApp=CreateObjec
6、t(Excel.application)IfexcelAppIsNothingThenExitSubEndIfEndIfexcelApp.Visible=TrueMe.MousePointer=vbHourglassexcelApp.Workbooks.AddWithexcelApp.ActiveSheetDimiAsInteger,jAsIntegerFori=1ToGrid1.rowsForj=1ToGrid1.Cols.Cells(i,j).value=&Grid1.TextMatrix(i-1),(j-1)加上“”号则能解决上面savegrid中银行帐号的导出问题。NextjDoEve
7、ntsNextiEndWithMe.MousePointer=vbDefaultSetexcelApp=NothingEndSubEXCEL同Vsflexgrid通过最近非常多的朋友,都想知道EXCEL怎样同VSflexgrid交换数据。实际上,利用“复制”、“粘贴”菜单即可实现。具体如下:(1)在Vsflexgrid上弹出右键菜单PrivateSubgrid1_MouseDown(ButtonAsInteger,ShiftAsInteger,XAsSingle,yAsSingle)ifButton=2ThenPopupMenumnutccdEndSub(2)设置各菜单的内容A复制Clipbo
8、ard.ClearClipboard.SetTextgrid1.ClipB剪切DimrowcAsLongDimrowzAsLongDimcolcAsLongdimcolzAsLongdimiaslongdimsaslongIfgrid1.Rows=1ThenExitSubClipboard.ClearClipboard.SetTextgrid1.ClipIfgrid1.RowSelgrid1.rowThenrowc=grid1.rowrowz=grid1.RowSelElserowc=grid1.RowSelrowz=grid1.rowEndIfIfgrid1.ColSelgrid1.ColT
9、hencolc=grid1.Colcolz=grid1.ColSelElsecolc=grid1.ColSelcolz=grid1.ColEndIfFori=rowcTorowzFors=colcTocolzgrid1.TextMatrix(i,s)=NextNextC粘贴(精华部分)DimiAsLongDimsAsLongDimmAsLongDimtAsLongIfgrid1.Rows=1ThenExitSubt=Len(Clipboard.GetText)Ift=0ThenExitSubFori=1TotIfMid(Clipboard.GetText,i,1)=Chr(9)Thens=s+
10、1IfMid(Clipboard.GetText,i,1)=Chr(13)Thenm=m+1NextIfs/(m+1)+grid1.Colgrid1.Cols-1Thengrid1.ColSel=grid1.Cols-1Elsegrid1.ColSel=s/(m+1)+grid1.ColEndIfIfgrid1.row+mgrid1.Rows-1Thengrid1.RowSel=grid1.Rows-1Elsegrid1.RowSel=grid1.row+mEndIfgrid1.Clip=Clipboard.GetTextVSFlexGrid常用属性或方法:.FixedRows=1固定几行.F
11、ixedCols=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,21
12、0)单元线条色.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(选项
13、准则,Row1,Col1,Row2,Col2)选择部分的相应准则值.EditCell当移动到当前单元时自动选择.EditSelStart移动到单元时的光标位置.MousePointer设置对象的鼠标指针样式O.A=0到15|99几个特别的属性方法的使用:FormatString属性:管道符格式化字符串示例:下面定义对齐方式同字意,列宽窄同距离VSG1.FormatString=中|右|右|中+搜索(查找)表格中符合条件的行:FindRow属性:该属性返回一个行值MsgBoxVSG1.FindRow(关键词,指定行,指定列,敏感,精度)关键词:String,表示要搜索的字符串指定行/指定列:Lo
14、ng,表示只在指定的行或列中找敏感:Boolean,限制只能在指定列输入(这里默认倒数第2列)PrivateSubVSG1_BeforeRowColChange(ByValOldRowAsLong,_ByValOldColAsLong,ByValNewRowAsLong,_ByValNewColAsLong,CancelAsBoolean)VSG1.Editable=flexEDKbdIfVSG1.RedrawflexRDNoneAndNewColVSG1.Cols-2ThenCancel=TrueVSG1.SelectNewRow,VSG1.Cols-2EndIfEndSub限制不能编辑某些
15、列:(这里限制第1列和第3列)PrivateSubVSG1_RowColChange()IfVSG1.Col=1OrVSG1.Col=3ThenVSG1.FocusRect=flexFocusNoneVSG1.Editable=flexEDNoneSendKeysElseVSG1.Editable=flexEDKbdSendKeysEndIfEndSub或:PrivateSubVSG1_RowColChange()IfVSG1.Col=1OrVSG1.Col=3ThenSendKeysElseSendKeysEndIfEndSub或:PrivateSubVSG1_RowColChange()I
16、fVSG1.Col=1OrVSG1.Col=3ThenVSG1.Editable=flexEDNoneElseVSG1.Editable=flexEDKbdVSG1.EditCell自动选择单元内容VSG1.EditSelStart=0选到最前|1选到指定|Len(VSG1.Text)选到最后EndIfEndSub对齐方式(-1标示所有).ColAlignment(-1)=flexAlignLeftCenter|flexAlignCenterCenter|flexAlignRightCenter示例1:(最后一行的第3列靠右对齐)VSG1.SelectVSG1.Rows-1,2VSG1.Cel
17、lAlignment=flexAlignRightCenter示例2:VSG1.Row=VSG1.Rows-1:VSG1.Col=1VSG1.CellAlignment=flexAlignRightCenter示例3:VSG1.Cell(flexcpAlignment,VSG1.Rows-1,1,VSG1.Rows-1,3)=flexAlignRightCenter本对象拖放:PrivateSubVSG1_MouseDown(ButtonAsInteger,_ShiftAsInteger,XAsSingle,YAsSingle)VSG1.DragVSG1.DragIcon=LoadPictur
18、e(D:Icon.ico)VSG1.DragRowVSG1.RowSelEndSub或从其他对象拖:PrivateSubVSG2_MouseDown(ButtonAsInteger,_ShiftAsInteger,XAsSingle,YAsSingle)VSG2.OLEDragVSG1.OLEDropMode=flexOLEDropAutomaticEndSubPublicSubVSGridCount(OptionalSelRowAsLong,OptionalSelColAsLong)DimXAsLong,iAsLongDimHj1,Hj2,Hj3AsStringConstA1=-922337
19、203685477#,A2=922337203685477#OnErrorGoToErrTransactWithfrmFG.VSG1X=.Rows-1.MergeCells=flexMergeFree.MergeRow(X)=True.Cell(flexcpText,X,0,X,1)=合计If.Rows=3Then.TextMatrix(X,0)=0.Cell(flexcpText,X,2,X,14)=.Cell(flexcpText,X,16,X,17)=¥0.00ExitSubEndIfHj1=Val(.Aggregate(flexSTSum,2,2,X-1,2)Hj2=Val(.Aggr
20、egate(flexSTSum,2,16,X-1,16)Hj3=CurrencyToStr(Hj2)Fori=2ToX-2Hj1=Hj1+Val(.TextMatrix(i,15)IfVal(.TextMatrix(i,16)0ThenHj2=Hj2+Val(.TextMatrix(i,15)*Val(.TextMatrix(i,16)EndIfNextiIfHj2=A2ThenGoToErrTransactEndIfHj3=CurrencyToStr(Hj2).TextMatrix(X,2)=Hj1.Cell(flexcpText,X,3,X,15)=IIf(Hj3=,Hj3).Cell(f
21、lexcpText,X,16,X,17)=Format(Hj2,¥0.00).Cell(flexcpAlignment,X,2,X,14)=flexAlignLeftCenter.SelectX,3.CellAlignment=flexAlignLeftCenterIfSelRow1AndSelCol0Then.SelectSelRow,SelColEndWithExitSubErrTransact:MsgBox你输入的数字过大无法计算!请修改!EndSub-将数字转换为大写金额的函数:FunctionCurrencyToStr(ByValNumberAsCurrency)AsStringNu
22、mber=Val(Trim(Number)IfNumber=0ThenCurrencyToStr=:ExitFunctionDimstr1AryAsVariant,str2AryAsVariantstr1Ary=Split(零壹贰叁肆伍陆柒捌玖)str2Ary=Split(分角元拾佰仟万拾佰仟亿拾佰仟万拾佰)DimaAsLong,bAsLong循环基数Dimtmp1AsString临时转换Dimtmp2AsString临时转换结果DimPointAsLong小数点位置IfNumber=922337203685477#ThenExitFunctionEndIftmp1=Round(Number,2)tmp1=Replace(
copyright@ 2008-2022 冰豆网网站版权所有
经营许可证编号:鄂ICP备2022015515号-1