How to use FlexGrid control (MSTOP (Chen Jianhua))

zhaozj2021-02-16  104

Below I will tell you about the properties, method events that MSHFLEXGRID, and some skills that can't be unknown.

1) Important properties of MSHFLEXGRID. Most of the properties of MSHFlexGrid, which is real, and the appearance of the display of the grid. In MSDN, these properties are enough to get people dazzled (I believe you have no pattability one Survey). The commonly used properties, method events and a brief description are listed below.

Property Type Description ALLOWBIGSELECTOR BOOLEAN Returns a value, defining whether the row or column will be selected by the entire selected AllowUseSizing Enum setting / return to a value when the header or column is clicked, defining the user to adjust the grid, Size BackColor Ole_Color Settings / Return Non-Fixed Unit Backcolorband Array / Ole_Color Settings / Return Background Color BachcolorBkg Ole_Color Settings / Return to Grid (Except for the Character Head) of each Independence BAND BACKCOLORFIXED OLE_COLOR Settings / Return to the background color backcolorheader array / ole_color setting / return grid head unit background color Backcolorindent Array / OLE_COLOR Settings / Return to the grid Backcolorsel OLE_COLOR Settings / Return Grid Select Unit Background Color BackcolorunPopulateD OLE_COLOR Settings / Return Grid Non User Operation Area Background Color BandData Array / Long for Unique Band Setting / Return Any Value, Determining BandbandDisplay Enum Definition in Grid by these values The BandExpandable Array / Boolen Setting / Return Value Independent BAND can be folded or expanded by the BandIndent Array / long definition BandLevel Long Return to the current unit included BANDS Long The total number of Cellalignment Integer Settings / Returns a value to define the horizontal and vertical alignment of the current unit CellbackColor OLE_COLOR Defines whether the font of the current unit is a bold cellfontbold boolean defined whether the current unit is bold CellFontitalic Boolean defines the current unit Whether the font is a slope CellFontName String definition of the statin of the current unit CellFontSize string Defines the font size of the current unit CellFontStrikeTHough Boolean Defines whether the font of the current unit is a sudden display CellFontunderLine Boolean definition of the current unit's font. CellfontWidth Single defines the font wide (point representation) CellFontColor OLE_COLOR Settings / Return the current cell's foreground color CellHeight Long Setting / Return the current cell CellLeft Long Returns the left side of the current cell CellPicture stdpicture setting / return current Picture of cells CellPictureAlignment Integer Settings / Returns image alignment of a current cell or a range of cells CellTextStyle Enum Settings / Return the current unit or selected range unit text 3D style Celltop Long Returns the vertical position of the current cell CellType Enum Setting / Returns the type of current cell (standard. Fixed) CellWidth long returns / sets the width of the current unit CLIP STRING Settings / Return Grid Selection Range Unit COL Array / Integer Settings / Return the horizontal coordinate of the current unit COLALNMENT ARRAY / INTEGER Setting / Return the current column alignment color setting / return BAND data column alignment collalignmentFixed Array / Integer Settings / Return Fixed Unit Data Alignment COLALIGNMENTHEADER ARRAY / INTEGER Settings / Return Fixed Head Unit Data Alignment COLDATA Ayyay / long is an independent column setting / returns any value,

Determining column colheader array / enum in the code Define whether each BAND header displays a column header display for each BAND column header display text ColisVisible Array / Boolen Back / Set No Colon is visible COLPOS Array / Long Returns a given column of the upper left corner and grid COLPSITION ARRAY / Long Settings Net Glone COLS long Back / Set the number of columns of the grid Column COLSEL Array / Long Settings / Return a range unit starting column ColWidth Array / Long Sets / returns the width of a column ColWordWrapOption Array / Integer set / return grid unit whether to permit the non-fixed WRAPColWordWrapOptionBand Array / Integer BAND defined grid is allowed WRAPColWordWrapOptionFixed Array / Integer defined fixed column Whether the unit allows WrapColWordWrapOptionHeader Array / Integer to define whether the header allows a separate column binding database field FillStyle Enum definition to change the other attributes of the text or unit affect all selected units or only affect the activity unit FixedCols long setting / Returns the number of columns for the fixed column FixedRows long setting / Return Row FocusRect Enum Define Controls The focus of the current unit represents Font StdFont Returns / Set the default font or all units FontBand Array / StdFont Settings / Return Each Band Use Text Font FontFixed Single Settings / Returns Fonts Fonts Fontheader Array / StdFont Settings / Return FontWidth Single Settings / Return Default Font Width FontWidthband Array / Single Settings / Return Band Wide Fontwidthfixed Single Settings / Return Fixwide FontWidthheader Array / Single Setting / Return Each Header For Forecolr Ole_Color Settings / Return to Grid Non-Fixed Unit Used Forecolorban D Array / OLE_COLOR Settings / Return Grid Each BAND Foreground ForecolorFixed OLE_COLOR Settings / Return Grid Fixed Unit The foreground color. ForecolorHeader Array / OLE_COLOR Settings / Return the foreground of the grid head unit Forecolorsel OLE_COLOR Settings / Return Settings Unit Prospects FormatString String defines a format string to set the width, alignment of the grid column,

Fixed line text fixed column text GridColor OLE_COLOR Settings / Return GridColorband Array / OLE_COLOR Settings / Return GridColorFixed Ole_Color Settings Returns GridColorHeader Array / Ole_ColorHeader Array / Ole_ColorHeader Array / OLE_COLOR Set / return color gridColorindent Ole_Color Settings / Return to GridColorUnPopulate_color Settings / Return GriglinesBand in Grigline Enum Defining GriglinesBand in GriglinesBand between the Grigline Enum between the Grigline Enum between the grid unpopulated Array / Enum Definition GrigLinesFixed Enum Defines GriglinesHeader Array / Enum Definition GriglineSindent Array / Enum Definition Grignesindent Array / Enum Definition Grid Indent ARRAY / ENUM type GrigLinesWidth Integer GrigLinesUnpopulated defined type is provided between the grid lines of the Enum UNPOPULATED region line / return line between the grid cell width GrigLinesWidthBand Array / Integer set / return line width GrigLinesWidthFixed Integer disposed between each of the grid BAND / return net GrigLinesWidthHeader Array line width of the compartment fixing unit / Integer set / return line width of the mesh between the heads GrigLinesWidthIndent Array / Integer set / return line between the grid unit width GrigLinesWidthUnpopulated Integer INDENT set / return area between the grid UNPOPULATED Width Hieght Enum definition how and when a high-brightness display grid is selected unit Leftcol long meter MRP Mergecells Enum setting / return a value indicates how to combine Mergecol Array / Boolen with a record of the same content Setting / Return A Value indicates which columns can merge the content merge Mergerow Array / Boolen setting / return a value indicate which rows can be merged with Mouseco. l Long Return Mouse Corpoal Location Mouselow Return Return Returns Picture Stardu Return Picture Stdpict Return to MshflexGrid Control Snapshot PictureType Enum Settings / Return to Picture Type RedRAW Boolean Settings / Return a value, indicating whether the MSHFLEXGRIDR control is heavy in each change Paint ROW long settings / Return the vertical coordinate RowData Array / long of the current unit to set any value for each row, to configure whether the rowpandable boolean defines whether the current line can expand whether ROWEXPANDED Boolean returns a value indicates that the current line Whether to expand RowHeight Array / Long Settings / Return High RowHeightmin Long Settings / Return to the Minimum Height Rowisvisible Array / Boolen Setting / Return a value of the grid,

Indicates that a particular column can be seen if rowpos array / long returns a given row, the left corner of the left corner of the MSHFLEXGRID control, RouwPosition Array / Long Setting a grid line Return Return to the total number of rows of the grid or or Band's row Total number ROWSEL long setting / Return a range of units ROWSIZINGMODE ENUM Settings / Return a value indicates that the settings of the row are all rows that affect the grid or only affect the adjusted row Scrollbars Enum setting / return a value indicates that MSHFLEXGRID The scroll bar type ScrollTrack Boolean setting / return a value indicates that the grid content changes the selectionMode Enum settings when the user moves the scroll bar, change the SelectionMode Enum setting / return a value indicates that the MFHFLEXGRID control allows the selected type .sort enum Some Village Preparation Set Sorting Value Text String Settings / Returns a unit or a range of internal units TextArray Array / String does not change the Row, COL attribute, setting / return to any unit text content TextMatrix array / string setting / return to a certain Selected line, column of text content text content TextStyle Enum Settings / Return Grid Usually 3D Text Style TextStyleband Array / Enum Settings / Return Grid Band 3D Text Style TextStyfixed Enum Settings / Return Grid Each Fixed Row 3D Text TEXTSTYLEHEADER ARRAY / ENUM Settings / Return Grid 3D Text Style Toprow Long Settings / Return Grid Top Objective Return Version Integer Returns WordWrap Boolean Definition When you arrive at the boundary of the unit, grid The content of the unit WRAP2) MSHFLEXGRID Control Important method Method Description AddITEM Add a new line of Clear to the grid Clearstructure Clear Grid's structure (mapping information) Collapseall folding grid's specific all Row EXPANDALL Expand Grid A specific row of REMOVEIITEMs Clear a line from the grid ADDITEM and REMOVEITEM can be used to add or delete rows to the grid. If folded or expanded all the lines of a BAN, COLLLAPSEALL can be used And ExpaandAll method. Method clear can clear the content in the grid, but does not affect the line of the grid, the number of columns, if you want to clear the structure of the grid, including the name of the order and the grid, should use the ClearsTRUCTURE method.

3) MSHFELXGRID's main event Collapse User Folded Grid One-line Compare When the Sort property is set to Customersort, allow the user to define the ordering process Entercell When a new unit is a current activity unit, the Expand user expands the grid Leavecell When a new unit becomes the current active unit RowColchange When a new unit becomes the current active unit, the scroll user uses the keyboard, the scroll bar scrolling the contents of the mesh or the content of the mesh, and the SELCHANGEVENT is selected.

Entercell, Leavecell, RowColchange events are interrelated, because the words are excited when a new unit becomes the current activity unit, in fact, the order of these events is: Leavecell, Entercell then is RowColchange.collapse and Expand events folded or expanded in users When the grid is one-line (BAND), the property Row and Col can be used to determine the user folded or expanded unit. When the sort property is set to 9, a Compare event is taken at each two lines of the grid, the user sorting method You can choose to sort in the afternial place or unit alignment. Note that the speed of using this sorting will be slower than build-in sorting. No matter what kind of method is used, as long as the grid is scrolling, the Scroll event will be excited. When the ScrollTrack property is set to TRUE, if the user is dragged or scrolling, the event is also excited. If the scrolltrack property is set to false, the scroll event is only excited once after the drag is over. When the cell changes When the SELCHANGEVENT event is excited, the change of the selected unit range can be implemented by user operation or program code. 1) MSHFLEXGRID editing. About MSHFLEXGRID editing, many books have an introduction. Generally use a TextBox as a Input box, by moving TextBox to achieve an editing function similar to Excel. Many books describe Move TextBox in the MouseDown or Click event, then write in the LeaveCell event. This article has similar situations, but There is also a small difference, mainly when writing to the grid, written in the TextBox's Change event .2) Save and load the grid content for the saving of the grid, the average person likes to use the .CLIP property, the entire grid In a file, of course, this is certainly a good way when the file is not big. However, when the grid reaches a few thousand rows, this method is not very good. (If you are interested If you can try the procedure below)

'Set the grid into 5000 * 12, then fill the grid with a random number. Then, call the following program Private submmand4_click () DIM MSGSTR AS STRING DIM FILEID AS Long Dim T1 AS DIM T2 AS DATE T1 = Timer () with MSHFLEXGRID1.ROW = 0 .col = 0.Rowsel = .ROWS - 1 .COLSEL = .cols - 1 fileId = freefile msgstr = .clip open "c: /lx.txt" for output as #fileid print #fileid, Msgstr Close #Fileid end with t2 = TIMER () MSGBOX T2 - T1END SUB Anyway my feelings is: It seems to be a dead machine, after a minute, the computer can react (measured 82.5 seconds, my computer is: AMD2500 , 512M memory). Why is the one-time write? This is probably a place that people can't think of. In fact, this is related to the mechanism of the VB processing string, if the 5k string should be one second, then The string of processing 30K is not 6 times the processing of 5K, but much longer. This relationship is almost a relationship with a certain geometric level. I understand that VB is the original to handle big strings. The effect is this. So. So The solution is natural. It is a word: demolished, will greatly speed up the speed of the string. Therefore, the main idea of ​​the following grid's preservation function will step by step Save, save a small part of each time. Until the entire grid is saved. Of course, there are some fine skills, for example: saving the total number of rows, columns, fixed lines, fixed columns in the grid, etc., Then, save the width of each column, then formally save the data. This is the convenient and fastness of loading. (Refer to the program below) Option Exprlicit

DIM M_ROW AS LONGDIM M_COL As Long

PRIVATE SUB Command3_Click () Fill Grid DIM R AS Long Dim C As Long for R = 0 To MSHFLEXGRID1.ROWS - 1 for c = 0 to mshflexGRID1.COLS - 1 MSHFLEXGRID1.TEXTMATRIX (r, c) = r & c next NEXTEND SUB

Private Sub Form_Load () with mshflexGrid1 text1.visible = false .rowHeight (-1) = 285 'Set the grid is 5000 rows .12 columns ..rows = 5000: .cols = 12 End Withend Sub

'Save PRIVATE SUB Command1_Click () Call Savefile (MshflexGrid1, "C: /kk.grd") End Sub

'Load file Private Sub Command2_Click () Call LoadFile (MSHFlexGrid1, "c: /kk.grd") End SubPrivate Sub MSHFlexGrid1_MouseDown (Button As Integer, Shift As Integer, x As Single, y As Single) Text1.Visible = False With MSHFlexGrid1 m_Row = .MouseRow m_Col = .MouseCol If m_Row <.FixedRows Then m_Row = .FixedRows If m_Col <.FixedCols Then m_Col = .FixedCols .Row = m_Row: .Col = m_Col Text1.Move .Left .CellLeft, .Top . Celltop, .cellwidth, .cellheight text1.text = .text text1.visible = true text1.setfocus End Withend Sub

Private sub text1_change () with mshflexGrid1 .textMatrix (m_row, m_col) = text1 End Withend Sub

'// ** The following is the corresponding function function' 'load a file to the table.' Function: loadFiletogrid 'parameter: msgobj mshfelxgrid control name, filename loaded file name' return value: = true success. = True failed .public function LoadFile (MsgObj As Control, FileName As String) As Long Dim InputID As Long, FileID As Long Dim EndRow As Long, DltAdd As Long Dim AddFlag As Boolean Dim keyTab As String, KeyEnter As String Dim FixedRows As Long, FixedCols As Long Dim GridInput As String, AddSum As String, RowColMax () As String Dim GridColMax As Long, GridRowMax As Long Dim OleRow As Long, OleCol As Long Dim SumFmtStr As String Dim DltCol As Long On Error Resume Next With MsgObj .Redraw = False Err.Clear: Setattr filename, 0 if err.Number <> 0 Then 'If the file does not exist Err.clear call savefile (msgobj, filename) .redraw = true exit function end if keytab = chr $ (vbkeytab): KeyEnter = chr $ (13) INPUTID = 0: addsum = "" addflag = false: dltd = 25: dltcol = 1 .redRAW = False: .fixedrows = 0: .fixedcols = 0 fileid = Freefile Open filename for Input as #fileid do while not eof (fileID) 'loops to the file end.

Line Input #fileId, GridInput if INPUTID <= 1 TEN 'Take the total number of banks and total columns, and the width of each column. If infuse = 0 Then Rowcolmax = Split (GridInput, "|") GridrowMax = ClNG ("0" & ​​" Rowcolmax (0)): GridColmax = ClNG ("0" & ​​rowcolmax (1)) IF ClNG ("0" & ​​rowcolmax (0)) <2 Then GridrowMax = 1 if ClNG ("0" & ​​RowColmax (1)) < 2 Then GridColMax = 1 .Rows = GridRowMax: .Cols = GridColMax Else SumFmtStr = GridInput 'format string End If Else If AddFlag Then AddSum = AddSum & KeyEnter & GridInput Else AddSum = GridInput: AddFlag = True End If If (InputID -. DLTCOL) MOD DLTADD = 0 Then.Row = INPUTID - DLTADD - DLTCOL: .COL = 0 .rowsel = INPUTID - 1 - D ltCol: .ColSel = GridColMax - 1 .Clip = AddSum: AddSum = "" EndRow = InputID - DltCol: AddFlag = False End If End If InputID = InputID 1 Loop If (InputID - DltCol) - EndRow> 1 Then .Row = Endrow: .col = 0.Rowsel = GridrowMax - 1 .COLsel = GridColmax - 1 .clip = addsum addresssum = ""

End if close #fileid call formatgrid (msgobj, sumfmtstr) .FixedRows = ClNG ("0" & ​​rowcolmax (2)): .fixedcols = clng ("0" & ​​rowcolmax (3)) .redraw = true .row = .fixedrows .Col = .fixedcols .rowsel = .fixedrows .colsel = .fixedcols end wirth = .fixedCOLS End welhend Function '' Save Table Data 'Function: Savefile' Parameters: Msgobj MSHFELXGRID Control Name, filename Loaded file name 'return value: = true success. = True. = True failure .Public Function SaveFile (MsgObj As Control, FileName As String) As Boolean '/ save file Dim FileID As Long, ConTents As String Dim A As Long, B As Long Dim RowMax As Long, ColMax As Long Dim FixRows As Long, FixCols As Long Dim OleRow As Long, OleCol As Long Dim SFmtStr As String Dim strColWidth As String On Error Resume Next With MsgObj .Redraw = False FixRows = .FixedRows: FixCols = .FixedCols RowMax = .Rows - 1: ColMax = .Cols - 1 .Fixedrows = 0: .fixedcols = 0 fileId = freefile

Open filename for output as #fileid contents = rowmax 1 & "& colmax 1 &" & fixrows & "|" & fixcols & "|" Print #fileId, Contents' Save the total number of rows and columns For a = 0 to .colmax strcolwidth = strcolwidth & .colwidth (a) & "|" Next Print #fileID, LEFT $ (StrColwidth - 1) 'Save the width of each column. For a = 0 TO RowMax .Row = A: .Col = 0 .RowSel = A: .ColSel = ColMax ConTents = .Clip Print #FileID, ConTents Next A Close #FileID .FixedRows = FixRows: .FixedCols = FixCols .Redraw = True End With SaveFile = (Err.Number = 0) Err.clerend Function 'Format Grid: Here is to set the grid width .Function formatGrid (MSGOBJ AS Control, FMTSTR AS STRING) DIM I As Long Dim with () AS String Withar = Split (FMTSTR , "|") For i = 0 to Ubound (Withar) if ISNUMERIC (WitharR (i)) THEN IF Val (WitharR (I))> 0 Then Msgobj.colwidth (i) = ClNG ("0" & ​​WITHARR (i)) end if nextend function

To automatically adjust the column width according to the content. As long as the text1_change function is appropriately modified, as follows:

Private Sub Text1_Change () Dim OleWidth As Long Dim NewWidth As Long With MSHFlexGrid1 .TextMatrix (m_Row, m_Col) = Text1 .Text = Text1 'auto column width according to an input NewWidth = Me.TextWidth (.Text)' a new column width OleWidth = .Cellwidth 'old column width if newwidth> OleWidth Then' If the new column is larger than the old column, set the column width to a new value. .Colwidth (.col) = newwidth text1.width = newwidth doevents end if End welhend Sub write a class, first determine its function. Expansion of a control function, nothing more than an attribute and method that does not have some original controls. As long as you have designed or designed controls, these relative are not difficult. This article assumes that the user has an experience that has been designed with a simple class. Features: Grid editing, file save, file load, keyboard movement (with arrow, Pageup, PageDown to left, down, turn the page, etc.), the grid is inserted, the grid is inserted into a column, delete one line, delete A column, delete content, delete columns within the range, and delete lines within the range. Implementation: For the editing, saving and loading of the grid. This is no longer described. For the movement of the keyboard, there is a difficult point here. Because we can't move the current table through the scroll of MshflexGrid, you can use a skill, which is: Move the edit box to the corresponding grid to implement the scroll function. For insert rows, it is very simple, essentially the "handling" of the content. For example, to insert a row in the current line, extend the grid, then move all the content down, and then clear the current line. The same is true for insertion columns. Only the row will become columns. It is simple to remove content within the scope. Deleting rows can directly delete the selected rows (MSHFLEXGRID provides the corresponding method), and the delete column is troublesome. First move the column before, then, reset the number of columns of the grid. Since the program is relatively long, I can't mention each part of the function, and there may be a bug. Of course, since I have a gallbladder to post this ointment, it is basically able to pass it. The properties and methods provided below:

** Property ** BindGrid binding table, such as: set bindgrid = mshflexGRID1. (This property is the most important property. You must first set) BindText Bind text box, such as: set bindtext = ev_text. (This property is the most important) Properties. You must first set it) BindPicture binding picture box, such as: set bindPicture = PictureBox1. (This property is the most important property. You must first set) EditFixed Can Edit fixed row .Enteraction Enter a behavior entertainment Enternextrow if it is right? Move to the end of the grid, whether to jump down. (Enteraction = true) PageEnable Can I turn the arrowEnable whether I can use an arrow to move edit box. DLTL input box left margins fine-tuning DLTT input box Total edge margin microconger DLTW input Box width fine curvation. DLTH input box height fine curvance. Outosize When the mesh is or not, whether the edit box can be automatically adjusted. ** Method **

Save Table Data Function: SaveFile Parameters: FileName Loaded File Name Return Value: = True Success. = False Failed.

Load a file to the form. Function: loadfiletogrid parameter: filename Loaded file name return value: = true success. = True failed.

Add a new row function to the table: addNewrow parameters: None. Return Value: None

Insert a blank line function before the table: INSERTROW parameters: InsRows Insert the number of spaces. Return Value:

In the table current column front plug column function: INSERTCOL parameter: Inscols inserted columns. Return Value:

Add a column function in the form: addnewcol parameter: return value:

Delete the current row function: DELGRIDROW parameter: return value:

Delete the current column function: DELGRIDCOL parameter: Return Value:

Delete the number of row numbers of the specified range: killgridrows parameters: Starrow delete start line, endrow delete end line. Return Value:

Delete the column number function of the specified range: killgridcols parameter: Starcol delete start column, endcol delete end column. Return Value:

Delete the content function of the specified range: killselgrid parameter: StarRow delete start row, start column of Starcol delete, end row, endcol delete and end column. Return Value: Application example: New project, add a PictureBox in the project , A TextBox, a MSHFLEXGRID control. Two buttons.

DIM M_EDITGRID AS New GridText.egridtext

Private Sub Form_Load () Dim A As Long with MshflexGrid1.Rows = 5001 .cols = 12 for a = 0 to .cols - 1 .COLWIDTH (A) = 900 Next for a = 0 to .rows - 1.TextMatrix (A, 0) = a Next end with '(focus): Note. Be sure before use. With m_editgrid set .bindgrid = mshflexgrid1 set .bindtext = text1 set .bindpicture = Picture1 .dltl = -15: .dltt = -15 .Autosize = true end wirth sub

'Save PRIVATE SUB Command1_Click () m_editgrid.savefile "C: /ASDF.GRD" End Sub' Load file private submmand2_click () m_editgrid.loadfile "c: /ASDF.GRD" End Sub

Let's go into the subject, the class is written. New project, select ActiveX DLL, set the project name as: gridtext, and Class1 is changed to EGRIDText. The word does not leak the following code. Then compile it to GridText.dll .. If To this class, the DLL is referenced in the project, referring to the example and description above.

'The following sections he is a formal code, for reference only and learn. CJWA @ 21cn.com

Option expedition

DIM LOSTFLAG AS BOOLLANDIM M_DLTL AS Long 'Left Increase DIM M_DLTT AS Long' Top Converaction DIM M_DLTW AS Long 'Wide Grocery DIM M_DLTH AS LONG' High Increment

'/ Can not be displayed to a user following properties .Public M_MoveFlag As BooleanPublic M_EditRow As LongPublic M_EditCol As LongPrivate M_AutoSize As Boolean' Auto size Private M_PageEnabled As Boolean 'page is valid Private M_ArrowEnabled As Boolean' arrow is valid Private M_EnterAction As Boolean 'ENTER behavior .Private M_EditFix As Boolean 'is editable fixed-line Private M_EnterNextRow As Boolean' If it is moved to the right end of the grid, whether to jump to the next line Dim M_Picture As VB.PictureBox '/ event declaration Private WithEvents Ev_GridObj As VBControlExtender' Define a general event for MSHFLEXGRID .private Withemts ev_text as vb.textbox 'Defines a Text event

'/'/******************Attributes******************

'Bindgrid binding table, such as: set bindgrid = mshflexGRID1. (This property is the most important property. You must first set) Public property get bindgrid () as object set bindgrid = ev_gridObjend Property

Public Property Set BindGrid (ByRef NewGrid As Object) If UCase $ (TypeName (NewGrid)) = UCase $ ( "MSHFlexGrid") Then Set Ev_GridObj = NewGrid 'event Else Set Ev_GridObj = Nothing MsgBox "This property can be bound to MSHFlexGrid! "& ChR $ (13) &" cjwa@21cn.com "& chr $ (13) &" (0668) 6422489, Vbokonly, "Error!" End IFEND Property

'BindText unbound text box, such as:. SET BindText = ev_text (. This is the most important attribute property must first set) Public Property Get BindText () As Object Set BindGrid = Ev_GridObjEnd PropertyPublic Property Set BindText (ByRef NewText As Object) If Ucase $ (NEPENAME (NEWTEXT)) = ucase $ ("TextBox") Then set ev_text = newtext 'event ev_text.text = "" ev_text.visible = false else set bindtext = nothing msgbox "This property can only be bound to TextBox! "& ChR $ (13) &" cjwa@21cn.com "& chr $ (13) &" (0668) 6422489, Vbokonly, "Error!" End IFEND Property

'Bindpicture binding picture box, such as: set bindPicture = PictureBox1. (This property is the most important property. You must first set) Public property get bindpicture () as object set bindpicture = m_picturend property

Public Property Set BindPicture (ByRef NewPicture As Object) If UCase $ (TypeName (NewPicture)) = UCase $ ( "PictureBox") Then Set M_Picture = NewPicture 'event M_Picture.Visible = False Else Set BindPicture = Nothing MsgBox "This property can only be Binds with Picturebox! "& Chr $ (13) &" cjwa@21cn.com "& chr $ (13) &" (0668) 6422489 ", Vbokonly," Error! "End IFEND Property

'EditFixed can edit fixed line .public property get ed editfixed () as boolean editfixed = m_editfixend profift

Public property let EditFixed (Byval NewValue As Boolean M_EDitfix = NewValueEnd Property

'Enteraction Enter Key Public Property Get Enteraction () AS Boolean Entection = M_ENTERACTIONEND PROPERTY

Public property Let Entection (Byval NewValue As Boolean) M_Enteraction = NewValueEnd Property

'EnterNextRow if it is moved to the right end of the grid, if a jump to the next row. (EnterAction = True) Public Property Get EnterNextRow () As Boolean EnterNextRow = M_EnterNextRowEnd PropertyPublic Property Let EnterNextRow (ByVal NewValue As Boolean) M_EnterNextRow = NewValueEnd Property

'PageENABLED can turn page Public Property Get PageNabled () as boolean pageenabled = m_pageenablededend print

Public Property Let PageENABLED (BYVAL NEWVALUE As Boolean) M_PageNabled = NewValueEnd Property

'Arrowenable can be edited with an arrow. Public property get arrowenabled () as boolean arrowenabled = m_arrowenabledend print

Public property let arrowenabled (byval newvalue as boolean) m_arrowenabled = newValueend Property

'DLTL input box left margin microconger PUBLIC PROPERTY GET DLTL () As long dltl = m_dltlend Property

Public Property Let DLTL (Byval NewValue As Long) M_dltl = NewValueEnd Property

'DLTT input box pin head distance microconger PUBLIC Property Get DLTT () as long dltt = m_dlttend Property

Public Property Let DLTT (BYVAL NEWVALUE AS Long) m_dltt = newvalueend property

'DLTW input box width microconger .public property get dLTW () as long dltw = m_dltwend property

Public Property Let DLTW (Byval NewValue As Long) M_dltw = NewValueEnd Property

'DLTH input box height fine curvation .Public property get dlth () as long dlth = m_dlthend property

Public Property Let DLTH (Byval NewValue As Long) M_dlth = NewValueEnd Property

'AutoSize When the mesh is or the column can change, whether the location of the edit box can be automatically adjusted .Public property get autosize () as boolean automation = m_autosizend property

Public property let autosize (byval newvalue as boolean) m_autosize = newvalueend property

'***********************method************************* * '/ Scroll in the event Private Sub GridScroll () on Error Resume Next Ev_Text.Visible = FalseEnd Sub' / KeyDown event in the Private Sub TextKeyDown (KeyCode As Integer) Dim EtxtSel As Long on Error Resume Next EtxtSel = Ev_Text.SelStart If EtxtSel = 0 Then If KeyCode = vbKeyLeft Then Call CodeMove (KeyCode) Exit Sub End If End If If EtxtSel = Len (Ev_Text.Text) Then If KeyCode = vbKeyRight Then Call CodeMove (KeyCode) Exit Sub End If End If If KeyCode = vbKeyDown Or KeyCode = vbKeyUp Or _ KeyCode = vbKeyTab Or KeyCode = vbKeyReturn Or _ KeyCode = vbKeyPageUp Or KeyCode = vbKeyPageDown _ Or KeyCode = vbKeyHome Or KeyCode = vbKeyEnd Then Call CodeMove (KeyCode) End IfEnd Sub

Private Sub Class_Initialize () M_AutoSize = False M_PageEnabled = True 'page is valid M_ArrowEnabled = True' arrow is valid M_EnterAction = True 'ENTER behavior. M_EditFix = False' can be edited fixed row M_MoveFlag = True M_EnterNextRow = TrueEnd Sub

'/ By binding in the event MSHFLEXGRID .Private Sub Ev_GridObj_ObjectEvent (Info As EventInfo)' / common event interface Select Case UCase $ (Info.Name) Case UCase $ ( "MouseDown") Call GridMouseDown Case UCase $ ( "Scroll" ) Call Gridscroll Case Ucase $ ("gotfocus")

Case Ucase $ ("MouseUp") Case Ucase $ ("Leavecell") 'occurs before the change occurs. Case Ucase $ ("Entercell")' Select changes. Case Ucase $ ("RowColchange") 'finally happened. End Selectnd Sub '/ TextChange' / return parameter: '/ Description: change event edit box .Private Sub Ev_Text_Change () Dim OleWidth As Long Dim newWidth As Long If Not (Ev_GridObj is Nothing) Then If Ev_GridObj.Visible And Ev_Text.Visible And M_AutoSize Then With M_Picture .Font.Name = Ev_Text.Font.Name .Font.Bold = Ev_Text.Font.Bold .Font.Italic = Ev_Text.Font.Italic .Font.Underline = Ev_Text.Font.Underline OleWidth = Ev_GridObj.ColWidth (M_EditCol ) NewWidth = .TextWidth (EV_TEXT "A") 'This here you can adjust it properly. There is a characteristic difference end with ev_gridobj if newwidth> olewidth damcolwidth (.col) = newwi dth Ev_Text.Width = NewWidth End If End With End If Ev_GridObj.TextMatrix (M_EditRow, M_EditCol) = Ev_Text End IfEnd Sub '/ keyboard events move edit box Private Sub CodeMove (KeyCode As Integer) Dim FixRows As Long, FixCols As Long Dim VisRow As Long On Error Resume Next M_MoveFlag = False VisRow = CLng (Ev_GridObj.Height / (Ev_GridObj.RowHeight (Ev_GridObj.Rows - 1) 37.5)) If M_EditFix Then FixRows = 0: FixCols = 0 Else FixRows = Ev_GridObj.FixedRows: FIXCOLS = EV_GRIDOBJ.FIXEDCOLS END IF

With Ev_GridObj Select Case KeyCode Case Is = vbKeyUp If M_ArrowEnabled Then If M_EditRow> FixRows Then M_EditRow = M_EditRow - 1 Else M_MoveFlag = True Exit Sub End If Else M_MoveFlag = True Exit Sub End If Case Is = vbKeyDown If M_ArrowEnabled Then If M_EditRow FixCols Then M_EditCol = m_Edit Col - 1 Else M_MoveFlag = True Exit Sub End If Else M_MoveFlag = True Exit Sub End If Case Is = vbKeyRight If M_ArrowEnabled Then If M_EditCol

True Exit Sub End If Case Is = vbKeyTab If M_EditCol FixCols

VisRow Then M_EditRow = M_EditRow - VisRow Else M_EditRow = FixRows End If Else M_MoveFlag = True Exit Sub End If Case Is = vbKeyPageDown If PageEnabled Then If M_EditRow

Ev_GridObj.FixedCols Ev_GridObj.SetFocus DoEvents With Ev_GridObj If M_MoveFlag Then M_EditRow = Ev_GridObj.MouseRow M_EditCol = Ev_GridObj.MouseCol If Not M_EditFix Then If M_EditRow <= FixRows - 1 Then M_EditRow = FixRows End If If M_EditCol <= FixCols - 1 Then M_EditCol = FixCols End If End If End If Ev_GridObj.Row = M_EditRow: Ev_GridObj.Col = M_EditCol DoEvents Ev_Text.Text = .Text L = .Left .CellLeft W = .cellwidth T = .Top .CellTop H = .CellHeight '/ edit moved block. Ev_Text.Move L DltL, T DltT, W DltW, H DltH Ev_Text.Font.Name = .CellFontName Ev_Text.ForeColor = .ForeColor Ev_Text.BackColor = .BackColor Ev_Text.Font.Size = .Font.Size EV_TEXT.Visible = true ev_text.setfocus end with m_moveflag = truend sub

'' Save Table Data 'Function: Savefile' Parameters: FileName Loaded File Name 'Return Value: = True Success. = False Failed .public Function Savefile (FileName As String) AS Boolean' / Save Document DIM FileID As long, Contents AS String Dim A As Long, B As Long Dim RowMax As Long, ColMax As Long Dim FixRows As Long, FixCols As Long Dim OleRow As Long, OleCol As Long Dim SFmtStr As String Dim strColWidth As String On Error Resume Next With Ev_GridObj .Redraw = False: m_moveflag = false fixrows = .fixedrows: fixcols = .fixedcols rowmax = .rowedcols - 1: colmax = .cols - 1 .fixedRows = 0: .fixedcols = 0 fileId = freefile

Open filename for output as #fileid contents = rowmax 1 & "& colmax 1 &" & fixrows & "|" & fixcols & "|" Print #fileId, Contents' Save the total number of rows and columns . For a = 0 to colmax strcolwidth = strcolwidth & .colwidth (a) & "|" Next Print #FileID, Left $ (StrColwidth - 1) 'Save the width of each column. For a = 0 to rowmax .Row = A: .Col = 0 .RowSel = A: .ColSel = ColMax ConTents = .Clip Print #FileID, ConTents Next A Close #FileID .FixedRows = FixRows: .FixedCols = FixCols .Redraw = True End With SaveFile = ( Err.Number = 0) m_moveflag = true err.clearend function 'loads a file to the form.' Function: loadFiletogrid 'parameter: FileName Loaded file name' return value: = true success. = True failed .public function loadFile (filename as STRING) AS Long Dim InputID AS Long, FileID As Long Dim Endrow As Long, DLTADD AS Long Dim Addflag As Boolean Dim K eyTab As String, KeyEnter As String Dim FixedRows As Long, FixedCols As Long Dim GridInput As String, AddSum As String, RowColMax () As String Dim GridColMax As Long, GridRowMax As Long Dim OleRow As Long, OleCol As Long Dim SumFmtStr As String Dim DltCol As Long On Error Resume Next With Ev_GridObj .Redraw = False: M_MoveFlag = False Err.Clear: SetAttr FileName, 0 If Err.Number <> 0 Then 'Err.Clear Call SaveFile (FileName) if the file does not exist .Redraw =

True EXIT FUNCTION END IF KeyTab = CHR $ (VBkeyTab): Keyenter = CHR $ (13) InputId = 0: addsum = "" addflag = false: dltd = 25: dltcol = 1 .redRAW = FALSE: .fixedROWS = 0:. FixedCOLS = 0 fileid = freefile open filename for input as #fileid do while not eof (fileID) 'loops to the file end.

Line Input #fileId, GridInput if INPUTID <= 1 TEN 'Take the total number of banks and total columns, and the width of each column. If infuse = 0 Then Rowcolmax = Split (GridInput, "|") GridrowMax = ClNG ("0" & ​​" Rowcolmax (0)): GridColmax = ClNG ("0" & ​​rowcolmax (1)) IF ClNG ("0" & ​​rowcolmax (0)) <2 Then GridrowMax = 1 if ClNG ("0" & ​​RowColmax (1)) < 2 Then GridColMax = 1 .Rows = GridRowMax: .Cols = GridColMax Else SumFmtStr = GridInput 'format string End If Else If AddFlag Then AddSum = AddSum & KeyEnter & GridInput Else AddSum = GridInput: AddFlag = True End If If (InputID -. DLTCOL) MOD DLTADD = 0 Then.Row = INPUTID - DLTADD - DLTCOL: .COL = 0 .rowsel = INPUTID - 1 - D ltCol: .ColSel = GridColMax - 1 .Clip = AddSum: AddSum = "" EndRow = InputID - DltCol: AddFlag = False End If End If InputID = InputID 1 Loop If (InputID - DltCol) - EndRow> 1 Then .Row = Endrow: .col = 0.Rowsel = GridrowMax - 1 .COLsel = GridColmax - 1 .clip = addsum addresssum = ""

End if close #fileid call formatgrid (SUMFMTSTR) .FixedRows = ClNG ("0" & ​​rowcolmax (2)): .fixedcols = clng ("0" & ​​rowcolmax (3)) .redraw = true .row = .fixedRows .col = .FixedCols .RowSel = .FixedRows .ColSel = .FixedCols End With M_MoveFlag = TrueEnd Function 'format grid: the grid width is provided here .Private Function FormatGrid (FmtStr As String) Dim I As Long Dim WithArr () As String

WITHARR = Split (FMTSTR, "|") for i = 0 to Ubound (Withar) IF ISNUMERIC (WITHARR (I)) "> 0 THEN EV_GRIDOBJ.COLWIDTH (i) = CLNG (" 0 "& WITHARR (i)) End if nextend function

Private sub ev_text_keydown (keycode as integer) Call textkeydown (keycode) End Sub

Add a new row 'function in the' 'table: addNewrow' parameter: None. 'Return Value: No public sub --dnewrow () DIM ROWID AS Long, b As long Dim Addflag as boolean ev_text.visible = false if m_editrow = ev_gridobj.rows - 1 Then AddFlag = False For RowID = Ev_GridObj.FixedCols To Ev_GridObj.Cols - 1 If Len (Trim $ (Ev_GridObj.TextMatrix (Ev_GridObj.Rows - 1, RowID)))> 0 Then AddFlag = True: Exit For End If Next RowId IF addflag kil_gridobj.rows = ev_gridobj.rows 1 end if End ifend sub

'' Table Current Row Plugd Quarter 'Functions: InSertrow' Parameters: InsRows Inserts Dark Quotes. 'Return Value: Public Sub Insertrow (Optional InsRows As Long = 1) DIM RS As Long, Rend As Long Dim Cs As Long , Cend As Long Dim MoveStr As String On Error Resume Next If InsRows <= 0 Then Exit Sub With Ev_GridObj Ev_Text.Visible = False .Redraw = False .Rows = .Rows InsRows For Rs = .Rows - InsRows - 1 To M_EditRow Step -1.Row = rs: .col = 0.Rowsel = rs: .colsel = .cols - 1 movester = .clip .row = rs insRows: .col = 0 .rowsel = rs insRoWs: .colsel = .cols - 1 .clip = MoveStr Next = m_EDitrow to m_EDitrow insRows - 1 for cs = 0 to .cols - 1 .TextMatrix (RS, CS) = "" "Next CS next rs .redraw = true end wirth sub ' Table Pattern Plus Column 'Functions: Insertcol' Parameters: Inscols Insert Columns. 'Return Value: Public Sub Insertcol (Optional Inscols As Long = 1) DIM RS As Long, REND AS Long Dim CS As Long, Cend As Long Dimestr AS String On Error ResMe Next If INSCOLS <= 0 THEN EXIT SUB

WITH EV_GRIDOBJ EV_TEXT.Visible = false .redraw = false .cols = .cols inscols for cs = .cols - inscols - 1 to m_editcol step -1 .row = 0: .col = cs.Rowsel = .ROWS - 1:. Colsel = cs movestr = .clip .row = 0: .col = cs inscols .rowsel = .rows - 1: .colsel = cs inscols .clip = movestr next cs for = 0 to .rows - 1 for cs = M_EDitcol to m_editcol inscols - 1.TextMatrix (RS, CS) = "" Next CS next rs .redraw = true endhend sub '' adds a column 'function in the table: addnewcol' parameters: 'Return Value: Public Sub AddNewcol () EV_GRIDOBJ.COLS = EV_GRIDOBJ.COLS 1 EV_Text.visible = Falsend Sub

'' Delete the current line 'function: DelgriDrow' parameters: 'Return Value: Public Sub Delgridrow () Dim MoveStr As String Dim Rowid As Long

EV_TEXT.Visible = false ev_gridobj.redraw = false ev_gridobj.removeItem m_editcol ev_gridobj.redraw = truend subend Sub

'' Delete the current column 'function: Delgridcol' parameters: 'Return Value: Public Sub Delgridcol () Dim MoveStr AS String Dim RowID As Long

Ev_Text.Visible = False Ev_GridObj.Redraw = False If M_EditCol = Ev_GridObj.Cols - 1 Then Ev_GridObj.Cols = Ev_GridObj.Cols - 1 Else For RowID = M_EditCol 1 To Ev_GridObj.Cols - 1 Ev_GridObj.Row = 0: Ev_GridObj.Col = RowID Ev_GridObj.RowSel = Ev_GridObj.Rows - 1: Ev_GridObj.ColSel = RowID MoveStr = Ev_GridObj.Clip Ev_GridObj.Row = 0: Ev_GridObj.Col = RowID - 1 Ev_GridObj.RowSel = Ev_GridObj.Rows - 1: Ev_GridObj.ColSel = RowID - 1 Ev_GridObj.Clip = MoveStr Next RowID If Ev_GridObj.Cols> 2 Then Ev_GridObj.Cols = Ev_GridObj.Cols - 1 End If End If If M_EditCol> Ev_GridObj.Cols - 1 Then M_EditCol = Ev_GridObj.Cols - 1 Ev_GridObj.Redraw = TrueEnd Sub

'' Remove the number of rows of the specified range 'function: killgridrows' parameters: Starrow delete start row, endrow delete end line.' Return Value: Public Sub KillgriDRows (Starrow As Long, endrow as long) Dim Rowid As Long, AddID AS Long, A As Long, B As Long Dim RemoArr () As Long Ev_Text.Visible = False Ev_GridObj.Redraw = False For RowID = StarRow To EndRow AddID = AddID 1 ReDim Preserve RemoArr (AddID) RemoArr (AddID - 1) = RowID Next If ArrEmpty (RemoArr) Then For RowID = 0 To UBound (RemoArr) - 1 Ev_GridObj.RemoveItem RemoArr (RowID) DoEvents If RowID <= UBound (RemoArr) - 1 Then For A = RowID To UBound (RemoArr) - 1 RemoArr ( A) = Remoarr (a) - 1 Next End IF next rowid end if ev_gridobj.redraw = trueEnd Sub 'Delete Specified Columns' Functions: KillGridCols 'Parameters: Starcol Delete Start Column, Endcol Delete End Column.' Returns Value: Public SUB KILLGRIDCOLS (Starcol As Long, Endcol As Long) Dim MoveStr AS String Dim Rowid As Long, Redcol As Long Ev_Text.Visible = FALSE Ev_GridObj.Redraw = False If M_EditCol = Ev_GridObj.Cols - 1 Then Ev_GridObj.Cols = Ev_GridObj.Cols - 1 Else For RowID = StarCol To Ev_GridObj.Cols - 1 RedCol = RowID EndCol - StarCol 1 If RedCol> Ev_GridObj.Cols - 1 Then Exit For Ev_GridObj.Row = 0: Ev_GridObj.Col = RedCol Ev_GridObj.RowSel = Ev_GridObj.Rows - 1: Ev_GridObj.ColSel = RedCol MoveStr = Ev_GridObj.Clip Ev_GridObj.Row = 0: Ev_GridObj.Col = RowID Ev_GridObj.RowSel = EV_GRIDOBJ.ROWS - 1: EV_GRIDOBJ.COLSEL =

RowID Next If Ev_GridObj.Cols> EndCol - StarCol 2 Then Ev_GridObj.Cols = Ev_GridObj.Cols - (EndCol - StarCol 1) End If If M_EditCol> Ev_GridObj.Cols - 1 Then M_EditCol = Ev_GridObj.Cols - 1 Ev_GridObj.Redraw = TrueEnd Sub '' Delete the content 'function: killselgrid' parameter: StarSelgrid 'parameter: StarRow Delete start row, start column of Starcol, end rows, endcol delete and end columns.' Return Value: Public Sub Killselgrid (Starrow AS Long, StarCol As Long, EndRow As Long, endCol As Long) Dim RowID As Long, B As Long Ev_Text.Visible = False For RowID = StarRow To EndRow For B = StarCol To endCol Ev_GridObj.TextMatrix (RowID, B) = "" Next next ev_gridobj.redraw = truend sub

The '/ array has been initialized.' / Function: arrempty '/ parameter: Myarr incoming data name.' / Return value: True has been initialized, false is not initialized. '/ Example: private function arrempty (byref myarr) AS Boolean Dim K as long on error resume next

K = ubound (myarr) if err.number <> 0 or K <0 Then Err.clear arrempty = false else arrempty = true end ifend function

转载请注明原文地址:https://www.9cbs.com/read-10777.html

New Post(0)