资源描述:
《VB中MSHFlexGrid的使用》由会员上传分享,免费在线阅读,更多相关内容在行业资料-天天文库。
1、VB-MSHFlexGrid的使用直接将查询数据填入MSHFLEXGRID:SubQueryFromSybasebyCon(Condition)WithQEvent‘QEvent为Form名称Con.OpenstrConnRemoters.CursorLocation=adUseClientrs.CursorType=adOpenKeysetOnErrorResumeNextRs.Open"select*where"&Condition&"orderbyevent_ts",Con,3,1‘Condition为SQL查询条件.MSHFlexGrid1.Redraw=Fa
2、lse‘重绘,可大大提高Grid的格式化后显示速度Set.MSHFlexGrid1.DataSourceRsSetRs=NothingSetCon=NothingEndWithEndSub2.设置MSHFlexGrid的格式SubFormatFlexGrid()WithQEvent.MSHFlexGrid1If.Rows>1And.TextMatrix(1,1)<>""Then'SetColumnwidth.ColWidth(0)=3000'SetColumnheader.TextMatrix(0,0)="Test"‘设置对齐.ColAlignment(5)=flex
3、AlignRightCenterEndIf‘设置整行的颜色.Redraw=False.Row=3.Col=0.ColSel=.Cols-1.CellBackColor=RGB(254,216,209).Redraw=TrueEndWithEndSub3.支持滚轮事件‘模块部分PublicCnAsNewADODB.ConnectionPublicConstGWL_WNDPROC=(-4)PublicConstWM_COMMAND=&H111PublicConstWM_MBUTTONDOWN=&H207PublicConstWM_MBUTTONUP=&H208Public
4、ConstWM_MOUSEWHEEL=&H20APublicOldwinprocAsLongPublicDeclareFunctionSetWindowLongLib"user32"Alias"SetWindowLongA"(ByValhwndAsLong,_ByValnIndexAsLong,ByValdwNewLongAsLong)AsLongPublicDeclareFunctionCallWindowProcLib"user32"Alias"CallWindowProcA"(ByVallpPrevWndFuncAsLong,_ByValhwndAsLong,B
5、yValMsgAsLong,ByValwParamAsLong,ByVallParamAsLong)AsLongPublicDeclareFunctionGetWindowLongLib"user32"Alias"GetWindowLongA"(ByValhwndAsLong,_ByValnIndexAsLong)AsLongPublicDeclareFunctionShellExecuteLib"shell32.dll"Alias"ShellExecuteA"(ByValhwndAsLong,ByVallpOperationAsString,ByVallpFileA
6、sString,ByVallpParametersAsString,ByVallpDirectoryAsString,ByValnShowCmdAsLong)AsLong‘支持鼠标动作的函数PublicFunctionFlexScroll(ByValhwndAsLong,ByValwMsgAsLong,ByValwParamAsLong,ByVallParamAsLong)AsLongSelectCasewMsgCaseWM_MOUSEWHEELSelectCasewParamCase-7864320'向下滚动SendKeys"{PGDN}"Case7864320'向
7、上滚动SendKeys"{PGUP}"EndSelectEndSelectFlexScroll=CallWindowProc(Oldwinproc,hwnd,wMsg,wParam,lParam)EndFunction‘窗体中的程序PrivateSubMSHFlexGrid1_GotFocus()Oldwinproc=GetWindowLong(Me.hwnd,GWL_WNDPROC)SetWindowLongMe.hwnd,GWL_WNDPROC,AddressOfFlexScrollEndSubPrivateSubMSHFlexGrid1_Los