MSHFlexGrid Control

The Microsoft Hierarchical FlexGrid (MSHFlexGrid) control displays and operates on tabular data. It allows complete flexibility to sort, merge, and format tables containing strings and pictures. When bound to a data control, MSHFlexGrid displays read-only data.

Syntax

MSHFlexGrid

Remarks

You can place text, a picture, or both in any cell of an MSHFlexGrid. The Row and Col properties specify the current cell in an MSHFlexGrid. You can specify the current cell using code, or the user can change it at run time using the mouse or the arrow keys. The Text property references the contents of the current cell.

If the text in a cell is too long to display in the cell, and the WordWrap property is set to True, the text wraps to the next line within the same cell. To display the wrapped text, you may need to increase the cell’s column width (ColWidth property) or row height (RowHeight property).

Use the Col and Row properties to determine the number of columns and rows in an MSHFlexGrid. Use the Band properties to determine the band styles in an MSHFlexGrid.

Displaying Hierarchical Recordsets

A major feature of the MSHFlexGrid control is its ability to display hierarchical recordsets—relational tables displayed in a hierarchical fashion. The easiest way to create a hierarchical recordset is to use the Data Environment designer and assign the DataSource property of the MSHFlexGrid control to the Data Environment. You can also create a hierarchical recordset in code using a Shape command as the RecordSource for an ADO Data Control, as shown in the example below:

' Create a ConnectionString.
Dim strCn As String
strCn = "Provider=MSDataShape.1;Data Source=Nwind;" & _
"Connect Timeout=15;Data Provider=MSDASQL"

' Create a Shape command.
Dim strSh As String
strSh = "SHAPE {SELECT * FROM `Customers`}  AS Customers " & _
"APPEND ({SELECT * FROM `Orders`}  AS Orders RELATE " & _
"CustomerID TO CustomerID) AS Orders"

' Assign the ConnectionString to an ADO Data Control's
' ConnectionString property, and the Shape command to the
' control's RecordSource property.
With Adodc1
   .ConnectionString = strCn
   .RecordSource = strSh
End With
' Set the HflexGrid control's DataSource property to the
' ADO Data control.
Set HFlexGrid1.DataSource = Adodc1

For More Information To find out more about hierarchical recordsets, see Hierarchical Cursors and Data Shaping Summary. A description of Shape commands can also be found in Shape Commands in General.

Note Before you can use an MSHFlexGrid in your application, you must add the MSHFlxGd.ocx file to your project. To automatically include the file in your project, put it in the Autoload file. When distributing your application, you should install the MSHFlxGd.ocx file in the user’s Microsoft Windows System directory. For more information about adding an ActiveX control to a project, see "Standard ActiveX Controls" in the Visual Basic Programmer’s Guide.


MSFlexGrid Control

The Microsoft FlexGrid (MSFlexGrid) control displays and operates on tabular data. It allows complete flexibility to sort, merge, and format tables containing strings and pictures. When bound to a Data control, MSFlexGrid displays read-only data.

Syntax

MSFlexGrid

Remarks

You can put text, a picture, or both, in any cell of an MSFlexGrid. The Row and Col properties specify the current cell in an MSFlexGrid. You can specify the current cell in code, or the user can change it at run time using the mouse or the arrow keys. The Text property references the contents of the current cell.

If the text in a cell is too long to display in the cell, and the WordWrap property is set to True, the text wraps to the next line within the same cell. To display the wrapped text, you may need to increase the cell’s column width (ColWidth property) or row height (RowHeight property).

Use the Col and Row properties to determine the number of columns and rows in an MSFlexGrid.

Note Before you can use an MSFlexGrid in your application, you must add the MSFlxGrd.ocx file to your project. To automatically include the file in your project, put it in the Autoload file. When distributing your application, you should install the MSFlxGrd.ocx file in the user’s Microsoft Windows System directory. For more information about adding an ActiveX control to a project, see "Standard ActiveX Controls" in the Visual Basic Programmer’s Guide.


Topic Not Found

No matching topic was found. Some possible reasons and remedies are as follows:

  • The file (.chm) that contains the destination topic is not in the expected location.

    Remedy: Rerun the MSDN Library Setup.

  • The file (.chm) that contains the current topic or destination topic is out-of-date and the link is no longer valid.

    Remedy: Install the latest version of the MSDN Library.

  • The MSDN Library CD is not in the CD-ROM drive.

    Remedy: Insert the MSDN Library CD into the CD-ROM drive.


MSHFlexGrid Error Constants

Constant | Value | Description
flexerrBadBandColIndex | 30020 | The specified band column index is invalid.
flexerrBadBandNumber | 30019 | The specified band number is invalid.
flexerrBadValue | 380 | The specified property value is invalid.
flexerrClipInvalidFormat | 461 | The specified format doesn't match the data format.
flexerrDataNotSetForFormat | 676 | The requested data was not supplied to the DataObject during the OLESetData event.
flexerrDataObjectLocked | 672 | The DataObject format list may not be cleared or expanded outside of the OLEStartDrag event.
flexerrExpectedAnArgument | 673 | At least one argument was expected.
flexerrFORMATSTRING | 30018 | Specify the row or column string to be formatted.
flexerrGetNotSupported | 394 | The specified property is not available.
flexerrHROWsNotReleased | 30023 | Unable to access the data. The DataSource property settings may be incorrect or the DataSource functionality may be limited.
flexerrIllegalFunctionCall | 5 | The specified procedure call is invalid.
flexerrNotAvailableWithBandedData | 30021 | The specified command is not available when bound to hierarchical data.
flexerrObjIllegalUse | 425 | The object use is invalid.
flexerrOutOfMemory | 7 | The system is running low on memory. Close any additional applications to free memory for your Visual Basic application.
flexerrRecursiveOLEDrag | 674 | Illegal recursive invocation of the OLE drag and drop.
flexerrSetNotPermitted | 387 | The specified setting is not permitted.
flexerrSubscript | 381 | The specified subscript is out of the allowable range.
flexerrUnknownBinding | 30022 | The Hierarchical FlexGrid does not support the requested type of data binding.
flexerrUnknownError | 600 | An error has occurred while performing the operation.
flexerrUserFormatNotBinArray | 675 | Non-intrinsic OLE drag and drop formats used with the SetData property require Byte array data. The GetData property may return more bytes than were provided to SetData.
flexerrVB30000 | 30000 | Cannot perform a RemoveItem on a fixed row.
flexerrVB30001 | 30002 | Cannot perform an AddItem on a fixed row.
flexerrVB30002 | 30004 | The Hierarchical FlexGrid does not contain the specified row.
flexerrVB30004 | 30005 | The column number specified for alignment is invalid.
flexerrVB30005 | 30005 | The specified alignment value is invalid.
flexerrVB30006 | 30006 | Unable to allocate memory for the Hierarchical FlexGrid.
flexerrVB30008 | 30008 | The specified picture type is invalid.
flexerrVB30009 | 30009 | The specified row value is invalid.
flexerrVB30010 | 30010 | The specified column value is invalid.
flexerrVB30011 | 30011 | Unable to register the memory manager.
flexerrVB30013 | 30013 | The specified row height value is invalid.
flexerrVB30014 | 30014 | The specified column width value is invalid.
flexerrVB30015 | 30015 | The last non-fixed row cannot be removed.
flexerrVB30016 | 30016 | The specified FixedRows value must be at least one less than the Rows value.
flexerrVB30017 | 30017 | The specified FixedCols value must be at least one less than the Cols value.


Collapse Event (MSHFlexGrid)

Occurs when the user collapses a row within the grid. The Col and Row properties of the MSHFlexGrid contain the cell used to collapse the band.

Syntax

Private Sub object_ Collapse(Boolean)

The Collapse event syntax has these parts:

Part | Description
object | An object expression that evaluates to an object in the Applies To list.
Boolean | A Boolean expression. If you set Cancel to True, the collapse is cancelled.


Compare Event

Occurs when the Sort property for the MSHFlexGrid is set to Custom Sort (9), so the user can customize the sort process.

Syntax

Private Sub object_Compare(row1, row2, cmp)

The Compare event syntax has these parts:

Part | Description
object | An object expression that evaluates to an object in the Applies To list.
row1 | A Long integer that specifies the first row in a pair of rows being compared.
row2 | A Long integer that specifies the second row in a pair of rows being compared.
cmp | An integer that represents the sort order of each pair, as described in Settings.

Settings

The event handler must compare row1 and row2 and set cmp to:

Setting | Description
–1 | If row1 should appear before row2.
0 | If both rows are equal or either row can appear before the other.
1 | If row1 should appear after row2.

Remarks

When the Sort property is set to 9 (Custom Sort), the Compare event occurs once for each pair of rows in the MSHFlexGrid. As the Compare event uses row numbers instead of text values, you can compare any property value for that row, including RowData.

Note While custom sorts are slower than built-in sorts, they provide the flexibility to sort a row by any column or using any cell property.


EnterCell Event

Occurs when the currently active cell changes to a different cell.

Syntax

Private Sub object_EnterCell()

The EnterCell event syntax has one part:

Part | Description
object | An object expression that evaluates to an object in the Applies To list.

Remarks

Clicking on a fixed row causes this event to occur on the first non-fixed column in that row. Dragging the mouse over a cell does not cause this event to occur.


Expand Event (MSHFlexGrid)

Occurs when the user expands a row within the MSHFlexGrid. The Col and Row properties of the MSHFlexGrid contain the cell used to expand the band.

Syntax

Private Sub object_Expand(Boolean)

The Expand event syntax has these parts:

Part | Description
object | An object expression that evaluates to an object in the Applies To list.
Boolean | A Boolean expression. If the developer sets Cancel to True, the collapse is cancelled.


FixedCols, FixedRows Properties (MSHFlexGrid) Example

The following code sets the first row and the first and second columns to fixed.

Note If you are using the MSFlexGrid, substitute "MSHFlexGrid1" with "MSFlexGrid1."

Sub Form1_Load ()
   MSHFlexGrid1.FixedCols = 2
   MSHFlexGrid1.FixedRows = 1
End Sub


FocusRect Property Example

The following code sets the focus rectangle for the active cell to a light rectangle, using the constant value.

Note If you are using the MSFlexGrid, substitute "MSHFlexGrid1" with "MSFlexGrid1."

Sub Form1_Load ()
   MSHFlexGrid1.FocusRect = flexFocusLight
End Sub


LeaveCell Event

Occurs immediately before the currently active cell changes to a different cell.

Syntax

Private Sub object_LeaveCell()

The LeaveCell event syntax has one part:

Part | Description
object | An object expression that evaluates to an object in the Applies To list.

Remarks

This event is used to validate the contents of a cell.

This event does not occur when moving focus to a different control.


RowColChange Event (MSHFlexGrid)

Occurs when the currently active cell changes to a different cell.

Syntax

Private Sub object_RowColChange()

The RowColChange event syntax has one part:

Part | Description
object | An object expression that evaluates to an object in the Applies To list.

Remarks

The following order of events occurs when the active cell changes: first LeaveCell, next EnterCell, finally RowColChange. The RowColChange event occurs when a user clicks a new cell. It does not occur while a user drags a selection across the MSHFlexGrid.


Scroll Event (MSHFlexGrid)

Occurs when the contents of the MSHFlexGrid are scrolled. This can be done using the scroll bars, keyboard, or programmatically by changing the TopRow or LeftCol properties.

Syntax

Private Sub object_Scroll()

The Scroll event syntax has one parts:

Part | Description
object | An object expression that evaluates to an object in the Applies To list.

Remarks

If the ScrollTrack property is True, this event occurs while the user is dragging or scrolling the mouse. If the ScrollTrack property is False, this event occurs once the drag is complete.


SelChange Event (MSHFlexGrid)

Occurs when the selected range changes to a different cell or range of cells.

Syntax

Private Sub object_SelChange()

The SelChange event syntax has these parts:

Part | Description
object | An object expression that evaluates to an object in the Applies To list.

Remarks

The SelChange event occurs when the user clicks a new cell, drags to select a new range of cells, or selects a range of cells by pressing and holding SHIFT while using the ARROW keys. This event does not occur while a user drags the selection across the MSHFlexGrid.

This event can occur programmatically by changing the selected region using the Row, Col, RowSel, or ColSel properties.


MSHFlexGrid Control Constants

This section contains information on the control constants of the MSHFlexGrid. Note that these constants also apply to the MSFlexGrid unless otherwise noted.

AddModeSettings Property (MSHFlexGrid)

Constant | Value | Description
flexNoAddNew | 0 | The current cell is not in the last row, and no AddNew operation is pending.
flexAddNewCurrent | 1 | The current cell is in the last row, but no AddNew operation is pending.
flexAddNewPending | 2 | The current cell is in the next to last row. This is a result of either a pending AddNew operation initiated by the user through the user interface of the MSHFlexGrid, or setting a column’s Value or Text property programmatically.

AllowUserResizing Property

Constant | Value | Description
flexResizeNone | 0 | The user cannot resize with the mouse. This is the default.
flexResizeColumns | 1 | The user can resize columns using the mouse.
flexResizeRows | 2 | The user can resize rows using the mouse.
flexResizeBoth | 3 | The user can resize columns and rows using the mouse.

Appearance Property

Constant | Value | Description
flexFlat | 0 | The overall look of MSHFlexGrid is flat, or normal.
flex3D | 1 | The overall look of MSHFlexGrid is three-dimensional.

BorderStyle Property

Constant | Value | Description
flexBorderNone | 0 | There is no border.
flexBorderSingle | 1 | There is a single border.

CellAlignment Property

Constant | Value | Description
flexAlignLeftTop | 0 | The cell content is aligned left, top.
flexAlignLeftCenter | 1 | The cell content is aligned left, center. This is the default for strings.
flexAlignLeftBottom | 2 | The cell content is aligned left, bottom.
flexAlignCenterTop | 3 | The cell content is aligned center, top.
flexAlignCenterCenter | 4 | The cell content is aligned center, center.
flexAlignCenterBottom | 5 | The cell content is aligned center, bottom.
flexAlignRightTop | 6 | The cell content is aligned right, top.
flexAlignRightCenter | 7 | The cell content is aligned right, center. This is the default for numbers.
flexAlignRightBottom | 8 | The cell content is aligned right, bottom.
flexAlignGeneral | 9 | The cell content is of general alignment. This is "left, center" for strings and "right, center" for numbers.

CellPictureAlignment Property

Constant | Value | Description
flexAlignLeftTop | 0 | The picture is aligned left, top.
flexAlignLeftCenter | 1 | The picture is aligned left, center.
flexAlignLeftBottom | 2 | The picture is aligned left, bottom.
flexAlignCenterTop | 3 | The picture is aligned center, top.
flexAlignCenterCenter | 4 | The picture is aligned center, center.
flexAlignCenterBottom | 5 | The picture is aligned center, bottom.
flexAlignRightTop | 6 | The picture is aligned right, top.
flexAlignRightCenter | 7 | The picture is aligned right, center.
flexAlignRightBottom | 8 | The picture is aligned right, bottom.

CellTextStyle, TextStyle, TextStyleFixed Properties

Constant | Value | Description
flexTextFlat | 0 | The text is normal, flat text.
flexTextRaised | 1 | The text appears raised.
flexTextInset | 2 | The text appears inset.
flexTextRaisedLight | 3 | The text appears slightly raised.
flexTextInsetLight | 4 | The text appears slightly inset.

CellType Properties (MSHFlexGrid)

Constant | Value | Description
flexCellTypeStandard | 0 | The cell is a standard cell.
flexCellTypeFixed | 1 | The cell is contained in a fixed row or column.
flexCellTypeHeader | 2 | The cell is a header cell for a band of data.
flexCellTypeIndent | 3 | The cell is used in a column that indents a band of data.
flexCellTypeUnpopulated | 4 | The cell is an unpopulated cell.

ColAlignment Properties

Constant | Value | Description
flexAlignLeftTop | 0 | The column content is aligned left, top.
flexAlignLeftCenter | 1 | The column content is aligned left, center. This is the default for strings.
flexAlignLeftBottom | 2 | The column content is aligned left, bottom.
flexAlignCenterTop | 3 | The column content is aligned center, top.
flexAlignCenterCenter | 4 | The column content is aligned center, center.
flexAlignCenterBottom | 5 | The column content is aligned center, bottom.
flexAlignRightTop | 6 | The column content is aligned right, top.
flexAlignRightCenter | 7 | The column content is aligned right, center. This is the default for numbers.
flexAlignRightBottom | 8 | The column content is aligned right, bottom.
flexAlignGeneral | 9 | The column content is of general alignment. This is left center for strings and right center for numbers.

ColHeader Property (MSHFlexGrid)

Constant | Value | Description
flexColHeaderOn | 0 | The headers display for each band.
flexColHeaderOff | 1 | No headers display for the band.
flexColHeaderOnce | 2 | The headers display for the band. If the band is collapsed, only one header displays. Duplicate headers don’t display.

DisplayBandSettings Property (MSHFlexGrid)

Constant | Value | Description
flexBandDisplayHorizontal | 0 | The bands within the MSHFlexGrid display horizontally (across). This is the default.
flexBandDisplayVertical | 1 | The bands within the MSHFlexGrid display vertically (up and down).

DisplayCellSettings Property (MSHFlexGrid)

Constant | Value | Description
FlexCellDisplayHorizontal | 0 | The bands within the MSHFlexGrid display horizontally (across).
flexCellDisplayVertical | 1 | The bands within the MSHFlexGrid display vertically (up and down).

FillStyle Property

Constant | Value | Description
flexFillSingle | 0 | Single. Changing Text or any of the cell properties only affects the active cell. This is the default.
flexFillRepeat | 1 | Repeat. Changing the Text or any of the cell properties affects all selected cells.

FocusRect Property

Constant | Value | Description
flexFocusNone | 0 | There is no focus rectangle around the current cell.
flexFocusLight | 1 | There is a light focus rectangle around the current cell. This is the default.
flexFocusHeavy | 2 | There is a heavy focus rectangle around the current cell.

GridLines, GridLinesFixed Properties

Constant | Value | Description
flexGridNone | 0 | No Lines. There are no lines between cells. In the MSFlexGrid, this is the default for GridLines.
flexGridFlat | 1 | Lines. The line style between cells is set to normal, flat lines. In the MSHFlexGrid, this is the default for GridLines.
flexGridInset | 2 | Inset Lines. The line style between cells is set to inset lines. In the MSFlexGrid, this is the default for GridLinesFixed.
flexGridRaised | 3 | Raised Lines. The line style between cells is set to raised lines. In the MSHFlexGrid, this is the default for GridLinesFixed.

HighLight Property

Constant | Value | Description
flexHighlightNever | 0 | There is no highlight on the selected cells.
flexHighlightAlways | 1 | The selected cells are always highlighted. This is the default.
flexHighlightWithFocus | 2 | The highlight appears only when the control has focus.

MergeCells Property

Constant | Value | Description
flexMergeNever | 0 | Never. The cells containing identical content are not grouped. This is the default.
flexMergeFree | 1 | Free. Cells with identical content always merge.
flexMergeRestrictRows | 2 | Restrict Rows. Only adjacent cells (to the left) within the row containing identical content merge.
flexMergeRestrict-Columns | 3 | Restrict Columns. Only adjacent cells (to the top) within the column containing identical content merge.
flexMergeRestrictBoth | 4 | Restrict Both. Only adjacent cells within the row (to the left) or column (to the top) containing identical content merge.

MousePointer Property

Constant | Value | Description
flexDefault | 0 | The outline of MSHFlexGrid.
flexArrow | 1 | An arrow pointer.
flexCross | 2 | A set of crosshairs.
flexIBeam | 3 | An "I"-shaped beam to allow for text entry.
flexIcon | 4 | A square within a square.
flexSize | 5 | A resizing pointer with arrows facing up, down, left, and right.
flexSizeNESW | 6 | A resizing pointer with arrows pointing to the upper right and lower left.
flexSizeNS | 7 | A resizing pointer with arrows pointing up and down.
flexSizeNWSE | 8 | A resizing pointer with arrows pointing to the upper left and lower right.
flexSizeEW | 9 | A resizing pointer with arrows pointing left and right.
flexUpArrow | 10 | An arrow pointing up.
flexHourGlass | 11 | An hourglass symbol.
flexNoDrop | 12 | A no drop pointer.
flexCustom | 13 | A custom style pointer.

PictureType Property

Constant | Value | Description
flexPictureColor | 0 | This produces a high-quality full-color image.
flexPictureMonochrome | 1 | This produces a lower-quality, monochrome, image that consumes less memory.

RowSizingSettings Property (MSHFlexGrid)

Constant | Value | Description
flexRowSizeIndividual | 0 | Resizing a row changes only the height of the row sized. This is the default.
flexRowSizeAll | 1 | Resizing a row changes the height of all rows in the MSHFlexGrid.

SelectionMode Property

Constant | Value | Description
flexSelectionFree | 0 | Free. This allows individual cells in the MSHFlexGrid to be selected, spreadsheet-style. (Default)
flexSelectionByRow | 1 | By Row. This forces selections to span entire rows, as in a multi-column list box or record-based display.
flexSelectionByColumn | 2 | By Column. This forces selections to span entire columns, as if selecting ranges for a chart or fields for sorting.

ScrollBars Property

Constant | Value | Description
flexScrollNone | 0 | The MSHFlexGrid has no scroll bars.
flexScrollHorizontal | 1 | The MSHFlexGrid has a horizontal scroll bar.
flexScrollVertical | 2 | The MSHFlexGrid has a vertical scroll bar.
flexScrollBoth | 3 | The MSHFlexGrid has horizontal and vertical scroll bars. This is the default.

Sort Property

Constant | Value | Description
flexSortNone | 0 | None. No sorting is performed.
flexSortGenericAscending | 1 | Generic Ascending. An ascending sort, which estimates whether text is string or number, is performed.
flexSortGenericDescending | 2 | Generic Descending. A descending sort, which estimates whether text is string or number, is performed.
flexSortNumericAscending | 3 | Numeric Ascending. An ascending sort, which converts strings to numbers, is performed.
flexSortNumericDescending | 4 | Numeric Descending. A descending sort, which converts strings to numbers, is performed.
flexSortStringNoCaseAsending | 5 | String Ascending. An ascending sort using case-insensitive string comparison is performed.
flexSortNoCaseDescending | 6 | String Descending. A descending sort using case-insensitive string comparison is performed.
flexSortStringAscending | 7 | String Ascending. An ascending sort using case-sensitive string comparison is performed.
flexSortStringDescending | 8 | String Descending. A descending sort using case-sensitive string comparison is performed.
flexSortCustom | 9 | Custom. This uses the Compare event to compare rows.


AddItem Method (MSHFlexGrid)

Adds a row to an MSHFlexGrid. This property doesn’t support named arguments.

Syntax

object.AddItem(string, index, number)

The AddItem method syntax has these parts:

Part | Description
object | An object expression that evaluates to an object in the Applies To list.
string | Required. A string expression displayed in the newly added row. To add multiple strings (for multiple columns in the row), use the tab character (vbTab) to separate each string.
index | Optional. A Long value indicating the position within the control. This position is where the new row is placed. For the first row, index=0. If index is omitted, the new row becomes the last row in the band. Note that index is BandColIndex in the MSHFlexGrid.
number | Optional. A Long value indicating the number of the band to which the row is added.

Remarks

If the MSHFlexGrid doesn’t contain any bands (it is bound to a non-hierarchical Recordset) the BandNumber parameter is optional. If specified it must be 0. If the BandDisplay property is set to horizontal and the MSHFlexGrid is bound to a hierarchical Recordset, the BandNumber parameter is required. If the BandDisplay property is set to vertical, the BandNumber parameter is only needed if the band is ambiguous. The index parameter is always optional.


AddItem, RemoveItem Methods (MSHFlexGrid) Example

This example uses the AddItem method to add 100 items to an MSHFlexGrid. To use this example, paste the code into the Declarations section of a form with an MSHFlexGrid named MSHFlexGrid1, press f5, and then click the form.

Note If you are using the MSFlexGrid, substitute "MSHFlexGrid1" with "MSFlexGrid1."

Private Sub Form_Click ()
   Dim Entry, i, Msg               ' Declare variables.
   Msg =_
   "Choose OK to add 100 items to your MSHFlexGrid."
   MsgBox Msg   ' Display message.
   MSHFlexGrid1.Cols =2         ' Two strings per row.
   For i =1 To 100   ' Count from 1 to 100.
      Entry ="Entry " & Chr(9) & I   ' Create entry.
      MSHFlexGrid1.AddItem Entry      ' Add entry.
   Next i
   Msg ="Choose OK to remove every other entry."
   MsgBox Msg                     ' Display message.
   For i =1 To 50               ' Determine how to
      MSHFlexGrid1.RemoveItem i   ' remove every other
   Next I                        ' item.
   Msg ="Choose OK to clear all items."
   MsgBox Msg                     ' Display message.
   MSHFlexGrid1.Clear               ' Clear list box.
End Sub


Clear Method (MSHFlexGrid)

Clears the contents of the MSHFlexGrid. This includes all text, pictures, and cell formatting. This method does not affect the number of rows and columns within the MSHFlexGrid.

Syntax

object.Clear

The Clear method syntax has one part:

Part | Description
object | An object expression that evaluates to an object in the Applies To list.

Remarks

To remove cells instead of just clearing them, use the RemoveItem method on each row to be removed.


Clear Method (MSHFlexGrid) Example

The following code places "Flex" into the current cell whenever the user clicks on a cell. When the user double-clicks, it clears the MSHFlexGrid. To run the program, press f5.

Note If you are using the MSFlexGrid, substitute "MSHFlexGrid1" with "MSFlexGrid1."

Private Sub Form1_Load ()
   MSHFlexGrid1.Rows =8
   MSHFlexGrid1.Cols =5
End Sub

Private Sub MSHFlexGrid1_Click ()
   ' Put text in current cell.
   MSHFlexGrid1.Text ="Flex"
End Sub

Private Sub MSHFlexGrid1.DblClick ()
   MSFlexGrid1.Clear
End Sub


ClearStructure Method (MSHFlexGrid)

Clears any mapping information from the MSHFlexGrid that regards the order and name of the displayed columns. This information may have been set at design time using the Band tab of the Property Pages dialog box or the Retrieve Structure command on the shortcut menu.

This method enables you to reset the MSHFlexGrid to a known state. If the user programmatically changes the underlying source of the MSHFlexGrid (and that source has a different structure), execute this method to properly display the data.

Syntax

object.ClearStructure

The ClearStructure method syntax has one part:

Part | Description
object | An object expression that evaluates to an object in the Applies To list.

Remarks

If the structure is changed without clearing the mapping information, the MSHFlexGrid attempts to display the new source with the existing mapping information. Only columns specified in the mapping information display data in the MSHFlexGrid. Other columns specified in the mapping information display but don’t show any data.


CollapseAll Method (MSHFlexGrid)

Collapses all rows of the specified band within the MSHFlexGrid.

Syntax

object.CollapseAll(number)

The CollapseAll property syntax has these parts:

Part | Description
object | An object expression that evaluates to an object in the Applies To list.
number | Optional. A Long value that specifies the band that contains the rows to collapse.


ExpandAll Method (MSHFlexGrid)

Expands all rows of the specified band within the MSHFlexGrid.

Syntax

object.ExpandAll(number)

The ExpandAll method syntax has these parts:

Part | Description
object | An object expression that evaluates to an object in the Applies To list.
number | Optional. A Long value that specifies the band that contains the rows to expand. If not specified, the default value is –1.


RemoveItem Method (MSHFlexGrid)

Removes a row from an MSHFlexGrid at run time. This property doesn’t support named arguments.

Syntax

object.RemoveItem(index, number)

The RemoveItem method syntax has these parts:

Part | Description
object | An object expression that evaluates to an object in the Applies To list.
index | An integer representing the row within the MSHFlexGrid to remove. For the first row, index=0.
number | A Long value that specifies the band from which to remove the row.

Remarks

This method deletes the entire row specified. To clear data without removing the rows, use the Clear method.

If the BandDisplay property is set to horizontal and the MSHFlexGrid is bound to a hierarchical Recordset, number is required. If the BandDisplay property is set to vertical, number is only needed if the band is ambiguous.

When removing a row within a band that contains child records, the child records are automatically removed.


AllowBigSelection Property

Returns or sets a value that determines whether clicking on a column or row header should cause the entire column or row to be selected.

Syntax

object.AllowBigSelection [=Boolean]

The AllowBigSelection property syntax has these parts:

Part | Description
object | An object expression that evaluates to an object in the Applies To list.
Boolean | A Boolean expression that specifies whether an entire column or row is selected when the header is clicked.

Settings

The settings for Boolean are:

Setting | Description
True | Default. When the user clicks the header, the entire column or row is selected.
False | When the user clicks the header, only the header is selected.


AllowBigSelection Property Example

The following code example allows an entire column or row to be selected when the user clicks on the header.

Note If you are using the MSFlexGrid, substitute "MSHFlexGrid1" with "MSFlexGrid1."

Sub Form1_Load ()
   MSHFlexGrid1.AllowBigSelection =True
End Sub


AllowUserResizing Property

Returns or sets a value that determines whether the user can use the mouse to resize rows and columns in the MSHFlexGrid.

Syntax

object.AllowUserResizing [=value]

The AllowUserResizing property syntax has these parts:

Part | Description
object | An object expression that evaluates to an object in the Applies To list.
value | An integer or constant that specifies whether a user can resize rows and columns, as described in Settings.

Settings

The settings for value are:

Constant | Value | Description
flexResizeNone | 0 | None. Default. The user cannot resize with the mouse.
flexResizeColumns | 1 | Columns. The user can resize columns using the mouse.
flexResizeRows | 2 | Rows. The user can resize rows using the mouse.
flexResizeBoth | 3 | Both. The user can resize columns and rows using the mouse.

Remarks

To resize rows or columns, the mouse must be over the fixed area of the MSHFlexGrid and close to a border between rows and columns. The mouse pointer changes into an appropriate sizing pointer, and the user can drag the row or column to change the row height or column width.


AllowUserResizing Property Example

The following code example adds user resizing functionality.

Note If you are using the MSFlexGrid, substitute "MSHFlexGrid1" with "MSFlexGrid1."

Sub Form1_Load ()
   MSHFlexGrid1.AllowUserResizing =True
End Sub


BackColorBand, BackColorHeader, BackColorIndent, BackColorUnpopulated Properties

  • BackColorBand — Returns or sets the background color of the band area of the MSHFlexGrid.

  • BackColorHeader — Returns or sets the background color of the header area of the MSHFlexGrid.

  • BackColorIndent — Returns or sets the background color of the indented area of the MSHFlexGrid.

  • BackColorUnpopulated — Returns or sets the background color of the unpopulated area of the MSHFlexGrid.

Syntax

object.BackColorBand [=color]
object.BackColorHeader [=color]
object.BackColorIndent [=color]
object.BackColorUnpopulated [=color]

Syntax for the BackColorBand, BackColorHeader, BackColorIndent, and BackColorUnpopulated properties has these parts:

Part | Description
object | An object expression that evaluates to an object in the Applies To list.
color | A numeric expression that specifies the color.


BackColor, BackColorBkg, BackColorFixed, BackColorSel Properties

Returns or sets the background color of various elements of the MSHFlexGrid.

Syntax

object.BackColor [=color]
object.BackColorBkg [=color]
object.BackColorFixed [=color]
object.BackColorSel [=color]

Syntax for the BackColor, BackColorBkg, BackColorFixed, and BackColorSel properties has these parts:

Part | Description
object | An object expression that evaluates to an object in the Applies To list.
color | A numeric expression that specifies the color.

Remarks

The picture below shows the part of the MSHFlexGrid to which the properties refer:

BackColor affects the color of all non-fixed cells. To set the background color of individual cells, use the CellBackColor property.


BackColor, BackColorBkg, BackColorFixed, BackColorSel Properties Example

The following example uses the BackColorBkg, BackColorFixed, and BackColorSel properties in the MSHFlexGrid. It resets the colors of the control's background, selected background, and fixed-cell background randomly twice each second for the MSHFlexGrid. To use this example, paste the code into the Declarations section of a form with a Timer control and an MSHFlexGrid with the names Timer1 and MSHFlexGrid1 respectively, then load the form.

Note If you are using the MSFlexGrid, substitute "MSHFlexGrid1" with "MSFlexGrid1."

Private Sub Form_Load ()
   Timer1.Interval =500
End Sub

Private Sub Timer1_Timer ()
   MSHFlexGrid1.BackColorBkg =QBColor(Rnd * 15)
   MSHFlexGrid1.BackColorFixed =QBColor(Rnd * 10)
   MSHFlexGrid1.BackColorSel =QBColor(Rnd * 10)
End Sub


BandColIndex Property (MSHFlexGrid)

Returns the column number of the current cell relative to the band that contains the cell.

Syntax

object.BandColIndex [=value]

The BandColIndex property syntax has these parts:

Part | Description
object | An object expression that evaluates to an object in the Applies To list.
value | A Long value that specifies the column number of the current cell.


BandDisplay Property (MSHFlexGrid)

Specifies how the bands display within the MSHFlexGrid.

Syntax

object.DisplayBandSettings [=value]

The BandDisplay property syntax has these parts:

Part | Description
object | An object expression that evaluates to an object in the Applies To list.
value | A numeric expression that specifies how the bands display within the MSHFlexGrid, as described in Settings.

Settings

The settings for value are:

Setting | Value | Description
flexBandDisplayHorizontal | 0 | Default. The bands within the MSHFlexGrid display horizontally (across).
flexBandDisplayVertical | 1 | The bands within the MSHFlexGrid display vertically (up and down).


BandExpandable Property (MSHFlexGrid)

Returns and sets a value that determines whether the row in the current band can be expanded and collapsed. The current band is defined by the Col and Row properties. This is a read-only property at run time and is not available at design time.

Syntax

object.BandExpandable(number) [=Boolean]

The BandExpandable property syntax has these parts:

Part | Description
object | An object expression that evaluates to an object in the Applies To list.
number | A Long value indicating the number of the band in the MSHFlexGrid.
Boolean | A Boolean expression that determines whether a specific band can be expanded and collapsed.

Settings

The settings for Boolean are:

Setting | Description
True | Default. The band specified can be expanded and collapsed.
False | The band specified cannot be expanded and collapsed.

Remarks

When a band is expandable, a standard plus (+) and minus (–) bitmap displays on the left of the first column within the band. This bitmap can be overridden by setting the ExpandPicture and CollapsePicture properties. When the grid first displays, all of the bands are collapsible by default.

Setting this property disables the user's capacity to expand or collapse the band; it doesn’t cause the rows within the specified band to expand or collapse. For example, if the child rows are shown before setting this property to False, the child rows continue to be shown after the setting.

For a band to be expandable, it must have at least one sub-band. Without a sub-band, the BandExpandable property is ignored.


BandIndent Property (MSHFlexGrid)

Specifies the number of columns by which to indent a band.

Syntax

object.BandIndent [=number]

The BandIndent property syntax has these parts:

Part | Description
object | An object expression that evaluates to an object in the Applies To list.
number | A Long value that specifies the band to be indented in the MSHFlexGrid. The default setting is 0.


BandLevel Property (MSHFlexGrid)

Returns the band number that contains the current cell. The band numbers begin at 0. The current cell is defined by the Col and Row properties. This property is not available at design time.

Syntax

object.BandLevel [=number]

The BandLevel property syntax has these parts:

Part | Description
object | An object expression that evaluates to an object in the Applies To list.
number | An integer or constant that specifies the band number that contains the current cell.


Bands Property (MSHFlexGrid)

Returns the total number of bands in an MSHFlexGrid. The MSHFlexGrid always has a minimum of one band. When the MSHFlexGrid is bound to a standard Recordset, the entire MSHFlexGrid is treated as one band.

Syntax

object.Bands [=value]

The Bands property syntax has these parts:

Part | Description
object | An object expression that evaluates to an object in the Applies To list.
value | The total number of bands in an MSHFlexGrid.

Remarks

This property is read-only. The number of Recordsets in the hierarchy of Recordsets with which the control is bound defines the value.

See the Col and Row properties.


CellAlignment Property

Returns or sets a value that determines the horizontal and vertical alignment of data within the current cell. This property is not available at design time.

Syntax

object.CellAlignment [=value]

The CellAlignment property syntax has these parts:

Part | Description
object | An object expression that evaluates to an object in the Applies To list.
value | An integer or constant that specifies how text should be aligned within the current cell, as described in Settings.

Settings

The settings for value are:

Constant | Value | Description
flexAlignLeftTop | 0 | The cell content is aligned left, top.
flexAlignLeftCenter | 1 | Default for strings. The cell content is aligned left, center.
flexAlignLeftBottom | 2 | The cell content is aligned left, bottom.
flexAlignCenterTop | 3 | The cell content is aligned center, top.
flexAlignCenterCenter | 4 | The cell content is aligned center, center.
flexAlignCenterBottom | 5 | The cell content is aligned center, bottom.
flexAlignRightTop | 6 | The cell content is aligned right, top.
flexAlignRightCenter | 7 | Default for numbers. The cell content is aligned right, center.
flexAlignRightBottom | 8 | The cell content is aligned right, bottom.
flexAlignGeneral | 9 | The cell content is of general alignment. This is "left, center" for strings and "right, center" for numbers.


CellAlignment Property Example

The following example sets the text alignment for each cell to left center using the constant setting.

Note If you are using the MSFlexGrid, substitute "MSHFlexGrid1" with "MSFlexGrid1."

Sub Form1_Load ()
   MSHFlexGrid1.CellAlignment =flexAlignLeftCenter
End Sub


CellBackColor, CellForeColor Properties

  • CellBackColor — Returns or sets the background colors of individual cells or cell ranges.

  • CellForeColor — Returns or sets the foreground colors of individual cells or cell ranges.

These properties are not available at design time.

Syntax

object.CellBackColor [=color]
object.CellForeColor [=color]

Syntax for the CellBackColor and CellForeColor properties has these parts:

Part | Description
object | An object expression that evaluates to an object in the Applies To list.
color | Integer (enumerated). A numeric expression that specifies the color for the current cell selection. Setting either of these properties to zero paints the cell using standard background and foreground colors.

Remarks

Changing this property affects the current cell or the current selection, depending on the setting of the FillStyle property.

Setting either of these properties to zero causes MSHFlexGrid to paint the cell using the standard background and foreground colors. If you want to set either of these properties to black, set them to one instead of zero.

To set the colors of various MSHFlexGrid elements, use the BackColorBkg, BackColorFixed, BackColorSel, ForeColorFixed, and ForeColorSel properties. To set all non-fixed cells to the same background color, use the BackColor property.


CellBackColor, CellForeColor Properties Example

The following example uses the CellBackColor and CellForeColor properties in MSHFlexGrid. It resets the background and text colors of the focused cell randomly twice each second for the MSHFlexGrid. To use this example, paste the following code into the Declarations section of a form with a Timer control and an MSHFlexGrid with the names Timer1 and MSHFlexGrid1 respectively, then load the form.

Note If you are using the MSFlexGrid, substitute "MSHFlexGrid1" with "MSFlexGrid1."

Private Sub Form_Load ()
   Timer1.Interval =500
   MSHFlexGrid1.Text ="Focus Here"
End Sub

Private Sub Timer1_Timer ()
   MSHFlexGrid1.CellBackColor =QBColor(Rnd * 15)
   MSHFlexGrid1.CellForeColor =QBColor(Rnd * 10)
End Sub


CellFontBold Property

Returns or sets the bold style for the current cell text. This property is not available at design time.

Syntax

object.CellFontBold [=Boolean]

The CellFontBold property syntax has these parts:

Part | Description
object | An object expression that evaluates to an object in the Applies To list.
Boolean | A Boolean expression that specifies whether the current cell's text is bold.

Settings

The settings for Boolean are:

Setting | Description
True | The current cell text is bold.
False | Default. The current cell text is normal (not bold).

Remarks

Changing this property affects the current cell or the current selection, depending on the setting of the FillStyle property.


CellFontBold Property Example

The following code sets the text of the current cell to bold whenever the MSHFlexGrid is in focus.

Note If you are using the MSFlexGrid, substitute "MSHFlexGrid1" with "MSFlexGrid1."

Sub MSHFlexGrid1_GotFocus()
   MSHFlexGrid1.CellFontBold =1
End Sub


CellFontItalic Property

Returns or sets the italic style for the current cell text. This property is not available at design time.

Syntax

object.CellFontItalic [=Boolean]

The CellFontItalic property syntax has these parts:

Part | Description
object | An object expression that evaluates to an object in the Applies To list.
Boolean | A Boolean expression that specifies whether the text style in the cell is italic.

Settings

The settings for Boolean are:

Setting | Description
True | The current cell text is italic.
False | Default. The current cell text is normal (not italic).

Remarks

Changing this property affects the current cell or the current selection, depending on the setting of the FillStyle property.


CellFontItalic Property Example

The following code sets the text of the current cell to Italic whenever the MSHFlexGrid is in focus.

Note If you are using the MSFlexGrid, substitute "MSHFlexGrid1" with "MSFlexGrid1."

Sub MSHFlexGrid1_GotFocus()
   MSHFlexGrid1.CellFontItalic =True
End Sub


CellFontName Property

Returns or sets the name of the font for the current cell text. This property is not available at design time.

Syntax

object.CellFontName [=string]

The CellFontName property syntax has these parts:

Part | Description
object | An object expression that evaluates to an object in the Applies To list.
string | A string expression naming one of the available font faces.

Remarks

Changing this property affects the current cell or the current selection, depending on the setting of the FillStyle property.


CellFontName Property Example

The following code sets the text of the current cell to a specific font type whenever the MSHFlexGrid is in focus.

Note If you are using the MSFlexGrid, substitute "MSHFlexGrid1" with "MSFlexGrid1."

Sub MSHFlexGrid1_GotFocus()
   MSHFlexGrid1.CellFontName =Screen.Fonts(3)
   MSHFlexGrid1.Text =Screen.Fonts(3)   ' Displays font
                                       ' name.
End Sub


CellFontSize Property

Returns or sets the size, in points, for the current cell text. This property is not available at design time.

Syntax

object.CellFontSize [=value]

The CellFontSize property syntax has these parts:

Part | Description
object | An object expression that evaluates to an object in the Applies To list.
value | Single. A numeric expression that specifies the size of the current cell text.

Remarks

Changing this property affects the current cell or the current selection, depending on the setting of the FillStyle property.


CellFontSize Property Example

The following code sets the text of the current cell to 12 points whenever the MSHFlexGrid is in focus.

Note If you are using the MSFlexGrid, substitute "MSHFlexGrid1" with "MSFlexGrid1."

Sub MSHFlexGrid1_GotFocus()
   MSHFlexGrid1.CellFontSize =12
End Sub


CellFontStrikeThrough Property

Returns or sets a value that determines if the Strikethrough style is applied to the current cell text.

Syntax

object.CellFontStrikeThrough =[Boolean]

The CellFontStrikeThrough property syntax has these parts:

Part | Description
object | An object expression that evaluates to an object in the Applies To list.
Boolean | A Boolean expression that specifies if the strike-through style is applied to the cell text.

Settings

The settings for Boolean are:

Setting | Description
True | The strikethrough style is applied to the cell text.
False | Default. The strikethrough style is not applied to the cell text.

Remarks

Changing the CellFontStrikeThrough property affects the current cell or the current selection, depending on the setting of the FillStyle property.


CellFontStrikeThrough Property Example

The following code sets the text of the current cell to the strikethrough style whenever the MSHFlexGrid is in focus.

Note If you are using the MSFlexGrid, substitute "MSHFlexGrid1" with "MSFlexGrid1."

Sub MSHFlexGrid1_GotFocus
   MSHFlexGrid1.CellFontStrikeThrough =1
End Sub


CellFontUnderline Property

Returns or sets a value that specifies if the underline style is applied to the current cell text.

Syntax

object.CellFontUnderline [=Boolean]

The CellFontUnderline property syntax has these parts:

Part | Description
object | An object expression that evaluates to an object in the Applies To list.
Boolean | A Boolean expression that specifies if the underline style is applied to the cell text.

Settings

The settings for Boolean are:

Setting | Description
True | The underline style is applied to the cell text.
False | Default. The underline style is not applied to the cell text.

Remarks

Changing the CellFontUnderline property affects the current cell or the current selection, depending on the setting of the FillStyle property.


CellFontUnderline Property Example

The following code sets the text of the current cell to Underline whenever the MSHFlexGrid is in focus.

Note If you are using the MSFlexGrid, substitute "MSHFlexGrid1" with "MSFlexGrid1."

Sub MSHFlexGrid1_GotFocus
   MSHFlexGrid1.CellFontUnderline =1
End Sub


CellFontWidth Property

Returns or sets the width, in points, for the current cell text. This property is not available at design time.

Syntax

object.CellFontWidth [=value]

The CellFontWidth property syntax has these parts:

Part | Description
object | An object expression that evaluates to an object in the Applies To list.
value | Single. A numeric expression that specifies the preferred point width for the current cell’s font.

Remarks

Changing the CellFontWidth property affects the current cell or the current selection, depending on the setting of the FillStyle property.


CellFontWidth Property Example

The following code sets the width of the text of the current cell when the MSHFlexGrid is in focus.

Note If you are using the MSFlexGrid, substitute "MSHFlexGrid1" with "MSFlexGrid1."

Sub MSHFlexGrid1_GotFocus()
   MSHFlexGrid1.CellFontWidth =5
End Sub


CellHeight, CellLeft, CellTop, CellWidth Properties (MSHFlexGrid)

Returns the position and size of the current cell, in twips. These properties are not available at design time.

Syntax

object.CellHeight [=value]
object.CellLeft [=value]
object.CellTop [=value]
object.CellWidth [=value]

Syntax for the CellHeight, CellLeft, CellTop, and CellWidth properties has these parts:

Part | Description
object | An object expression that evaluates to an object in the Applies To list.
value | A numeric expression that specifies the return position or size of the current cell.

Remarks

These properties are useful if you want to emulate in-cell editing. By trapping the MSHFlexGrid's KeyPress event, you can place a text box or some other control over the current cell and let the user edit its contents.

The return values are always in twips, regardless of the form’s ScaleMode setting.


CellPictureAlignment Property

Returns or sets the alignment of pictures in a cell or range of selected cells. This property is not available at design time.

Syntax

object.CellPictureAlignment [=value]

The CellPictureAlignment property syntax has these parts:

Part | Description
object | An object expression that evaluates to an object in the Applies To list.
value | An integer or constant that specifies how pictures should be aligned within cells, as described in Settings.

Settings

The settings for value are:

Constant | Value | Description
flexAlignLeftTop | 0 | The picture is aligned left, top.
flexAlignLeftCenter | 1 | The picture is aligned left, center.
flexAlignLeftBottom | 2 | The picture is aligned left, bottom.
flexAlignCenterTop | 3 | The picture is aligned center, top.
flexAlignCenterCenter | 4 | The picture is aligned center, center.
flexAlignCenterBottom | 5 | The picture is aligned center, bottom.
flexAlignRightTop | 6 | The picture is aligned right, top.
flexAlignRightCenter | 7 | The picture is aligned right, center.
flexAlignRightBottom | 8 | The picture is aligned right, bottom.

Remarks

Changing this property affects the current cell or the current selection, depending on the setting of the FillStyle property.

The FillStyle property must be set to 1 (Repeat) for CellAlignment to align a range of selected cells within the MSHFlexGrid.


CellPictureAlignment Property Example

The following code sets the picture alignment of the current cell to right center using the constant value.

Note If you are using the MSFlexGrid, substitute "MSHFlexGrid1" with "MSFlexGrid1."

Sub Form1_Load
   MSHFlexGrid1.CellPictureAlignment =_
   flexAlignRightCenter
End Sub


CellPicture Property

Returns or sets an image to be displayed in the current cell or range of cells. This property is not available at design time.

Syntax

object.CellPicture [=picture]

The CellPicture property syntax has these parts:

Part | Description
object | An object expression that evaluates to an object in the Applies To list.
picture | A bitmap, icon, or metafile graphic. This can be assigned to another control’s Picture property.

Remarks

You can set this property at run time using the LoadPicture function on a bitmap, icon, or metafile, or by assigning to it another control’s Picture property.

Changing this property affects the current cell or the current selection, depending on the setting of the FillStyle property.

Each cell may contain text and a picture. The relative position of the text and picture is determined by the CellAlignment and CellPictureAlignment properties.


CellPicture Property Example

The following example loads icons from the Visual Basic icon library into two cells within an MSHFlexGrid. You can use any two icons. Paste the code into the Declarations section of a form that contains the MSHFlexGrid. Press f5 to run the program, and then click the form.

Private Sub Form_Click ()
   ' Load the icons.
   MSHFlexGrid1.Row =1
   MSHFlexGrid1.Col =1
   Set MSHFlexGrid1.CellPicture =_
   LoadPicture("Icons\Computer\Trash02a.ico")
   MSHFlexGrid1.Row =1
   MSHFlexGrid1.Col =2
   Set MSHFlexGrid1.CellPicture =_
   LoadPicture("Icons\Computer\Trash02b.ico")
End Sub


CellTextStyle Property

Returns or sets the three-dimensional style for text in a specific cell or range of cells. This property is not available at design time.

Syntax

object.CellTextStyle [=value]

The CellTextStyle property syntax has these parts:

Part | Description
object | An object expression that evaluates to an object in the Applies To list.
value | An integer or constant that specifies one of the constants of the CellTextStyle property, as described in Settings.

Settings

The settings for value are:

Constant | Value | Description
flexTextFlat | 0 | Default. The text is normal, flat text.
flexTextRaised | 1 | The text appears raised.
flexTextInset | 2 | The text appears inset.
flexTextRaisedLight | 3 | The text appears slightly raised.
flexTextInsetLight | 4 | The text appears slightly inset.

Remarks

Settings 1 and 2 work best for large and bold fonts. Settings 3 and 4 work best for small regular fonts. The cell’s appearance is also affected by the BackColor settings; some BackColor settings do not show the raised or inset feature.

Changing this property affects the current cell or the current selection, depending on the setting of the FillStyle property.


CellTextStyle Property Example

The following code sets the text style of the current cell or current selection to inset using the constant value.

Note If you are using the MSFlexGrid, substitute "MSHFlexGrid1" with "MSFlexGrid1."

Sub MSHFlexGrid1_GotFocus
   MSHFlexGrid1.CellTextStyle =flexTextInset
End Sub


CellType Property (MSHFlexGrid)

Returns the type of the current, active, cell of the MSHFlexGrid.

Syntax

object.CellType [=value]

The CellType property syntax has these parts:

Part | Description
object | An object expression that evaluates to an object in the Applies To list.
value | A Long value that specifies the position of the active cell, as described in Settings.

Settings

The settings for value are:

Constant | Value | Description
flexCellTypeStandard | 0 | Default. The cell is a standard cell.
flexCellTypeFixed | 1 | The cell is contained in a fixed row or column.
flexCellTypeHeader | 2 | The cell is a header cell for a band of data.
flexCellTypeIndent | 3 | The cell is used in a column that indents a band of data.
flexCellTypeUnpopulated | 4 | The cell is an unpopulated cell.


Clip Property (MSHFlexGrid)

Returns or sets the contents of the cells in the MSHFlexGrid's selected region. This property is not available at design time.

Syntax

object.Clip [=string]

The Clip property syntax has these parts:

Part | Description
object | An object expression that evaluates to an object in the Applies To list.
string | A string expression with the contents of the selected area.

Remarks

The string may hold the contents of multiple rows and columns. In string, a tab character, Chr (9), or the constant vbTab indicates a new cell in a row. Also in string, a carriage return, Chr (13), or the constant vbCR indicates the beginning of a new row. Use the Chr function or the vb constants to embed these characters in strings.

When placing data into an MSHFlexGrid, only the selected cells are affected. If there are more cells in the selected region than are described in the string, the remaining cells are left alone. If there are more cells described in the string than there are in the selected region, the unused portion of string is ignored.


Clip Property (MSHFlexGrid) Example

The following code example places the names James, Nancy, and Lisa into the selected cells whenever the user selects a group of cells. When the user double-clicks, it clears the MSHFlexGrid. To run the program, press f5.

Note If you are using the MSFlexGrid, substitute "MSHFlexGrid1" with "MSFlexGrid1."

Private Sub Form1_Load ()
   MSHFlexGrid1.Rows =8
   MSHFlexGrid1.Cols =5
End Sub

Private Sub MSHFlexGrid1_MouseUp (Button As Integer, _
Shift as Integer, X As Single, Y As Single)
Dim myStr As String
   myStr ="James" + Chr(9) + "Nancy" + Chr(9) + "Lisa"
   MSHFlexGrid1.Clip =myStr
End Sub


ColAlignment, ColAlignmentBand, ColAlignmentHeader Properties (MSHFlexGrid)

Returns or sets the alignment of data in a column. This can be a standard column, a column within a band, or a column within a header. This property is not available at design time (except indirectly through the FormatString property).

Syntax

object.ColAlignment(number) [=value]
object.ColAlignmentBand(number) [=value]
object.ColAlignmentHeader(number) [=value]

Syntax for the ColAlignment, ColAlignmentBand, and ColAlignmentHeader properties has:

Part | Description
object | An object expression that evaluates to an object in the Applies To list.
number | A Long value that specifies the number of the column in the MSHFlexGrid.
value | An integer or constant that specifies the alignment of data in a column, as described in Settings.

Settings

The settings for value are:

Constant | Value | Description
flexAlignLeftTop | 0 | The column content is aligned left, top.
flexAlignLeftCenter | 1 | Default for strings. The column content is aligned left, center.
flexAlignLeftBottom | 2 | The column content is aligned left, bottom.
flexAlignCenterTop | 3 | The column content is aligned center, top.
flexAlignCenterCenter | 4 | The column content is aligned center, center.
flexAlignCenterBottom | 5 | The column content is aligned center, bottom.
flexAlignRightTop | 6 | The column content is aligned right, top.
flexAlignRightCenter | 7 | Default for numbers. The column content is aligned right, center.
flexAlignRightBottom | 8 | The column content is aligned right, bottom.
flexAlignGeneral | 9 | The column content is of general alignment. This is "left, center" for strings and "right, center" for numbers.

Remarks

Any column can have an alignment that is different from other columns. The ColAlignment property affects all cells in the specified column, including those in fixed rows.

To set individual cell alignments, use the CellAlignment property. To set column alignments at design time, use the FormatString property.

If the MSHFlexGrid is in vertical mode, the setting ColAlignment(3) may affect columns in multiple bands.


ColAlignment Property (MSHFlexGrid) Example

The following code sets the alignment of the third column to "right, center" using the constant value.

Note If you are using the MSFlexGrid, substitute "MSHFlexGrid1" with "MSFlexGrid1."

Sub Form1_Load ()
   MSHFlexGrid1.ColAlignment(3) =flexAlignRightCenter
End Sub


ColData, RowData, BandData Properties (MSHFlexGrid)

Returns or sets an arbitrary long value associated with each row, column, or band. These properties are not available at design time.

Syntax

object.ColData(number) [=value]
object.RowData(number) [=value]
object.BandData(number) [=value]

Syntax for the ColData, RowData, and BandData properties has these parts:

Part | Description
object | An object expression that evaluates to an object in the Applies To list.
number | A Long value that specifies the column, row, or band in the MSHFlexGrid. This number indicates where to save or retrieve the data.
value | A Long value that specifies the contents of the ColData, RowData, or BandData arrays.

Remarks

Use the RowData, ColData, and BandData properties to associate a specific number with each row, column, or band on an MSHFlexGrid. Once a number is associated with each row, column, or band, you can use the numbers programmatically to identify the items.

You can add rows containing totals to an MSHFlexGrid and identify those rows by setting their RowData property to a non-zero value. To update the totals, you can delete the old totals by scanning the RowData array and removing the appropriate rows.

Another typical use of the RowData property is to keep an index in an array of data structures associated with the items described in each row.


ColHeaderCaption Property (MSHFlexGrid)

Specifies the caption to display in the header of the specified column and band.

Syntax

object.ColHeaderCaption(number, index) [=string]

The ColHeaderCaption property syntax has these parts:

Part | Description
object | An object expression that evaluates to an object in the Applies To list.
number | A Long value that indicates the band that contains the specified column to set the caption.
index | A Long value that indicates the specified column.
string | A string expression that specifies one of the available font types.


ColHeader Property (MSHFlexGrid)

Specifies whether headers should display for the specified band.

Syntax

object.ColHeader(value)

The ColHeader property syntax has these parts:

Part | Description
object | An object expression that evaluates to an object in the Applies To list.
value | Optional. A Long value that specifies whether the band that contains the headers will show or be hidden, as described in Settings.

Settings

The settings for value are:

Settings | Value | Description
flexColHeaderOn | 0 | The headers display for each band.
flexColHeaderOff | 1 | No headers display for the band.
flexColHeaderOnce | 2 | The headers display for the band. If the band is collapsed, only one header displays. Duplicate headers don’t display.


ColIsVisible Property

Returns or sets a value indicating whether a specified column is currently visible.

Syntax

object.ColIsVisible(index) [=Boolean]

The ColIsVisible property syntax has these parts:

Part | Description
object | An object expression that evaluates to an object in the Applies To list.
index | A Long value that specifies the column.
Boolean | A Boolean expression that specifies whether the specified column is visible.

Settings

The settings for Boolean are:

Setting | Description
True | Default. The specified column is visible.
False | The specified column is not visible.


ColPosition, RowPosition Properties

  • ColPosition — Sets the position of an MSHFlexGrid column, allowing you to move columns to specific positions.

  • RowPosition — Sets the position of an MSHFlexGrid row, allowing you to move rows to specific positions.

Syntax

object.ColPosition(index, number) [= value]
object.RowPosition(number) [= value]

Note The above ColPosition syntax cannot be used in an MSFlexGrid due to the limitations of this control. If you are using MSFlexGrid, use the syntax: object.ColPosition(number) [= value]

Syntax for the ColPosition and RowPosition properties has these parts:

Part | Description
Object | An object expression that evaluates to an object in the Applies To list.
index A Long value that specifies the column to be moved.

Note This is not applicable to the MSFlexGrid.
number A Long value that specifies the band containing the column to be moved. Optional.

Note In the MSFlexGrid, this is the number of the column or row to be moved.
value | Integer. A numeric expression that specifies the new position of the column or row.

Remarks

In the MSHFlexGrid, when BandNumber is not specified, it defaults to 0. Hence, when the grid is not bound to a hierarchical Recordset, using 0 for BandNumber and not specifying BandNumber both have the same result. Note that BandNumber is an optional parameter for backward compatibility with the MSFlexGrid.

The index and setting must correspond to valid row or column numbers (in the range 0 to Rows –1 or Cols –1), otherwise an error is generated.

When a row or column is moved using the RowPosition and ColPosition properties, all formatting information moves with it. This includes width, height, alignment, colors, and font properties. To move text only, use the Clip property.


ColPosition Property Example

When implemented, the following code causes a column to move to the first position (the left-most column) when the user clicks on the column.

Note If you are using the MSFlexGrid, substitute "MSHFlexGrid1" with "MSFlexGrid1."

Sub MSHFlexGrid1_Click ()
   MSHFlexGrid1.ColPosition(MSFlexGrid1.MouseCol) = 0
End Sub


Col, Row Properties (MSHFlexGrid)

Returns or sets the coordinates of the active cell in an MSHFlexGrid. These properties are not available at design time.

Syntax

object.Col [=number]
object.Row [=number]

Syntax for the Col and Row properties has these parts:

Part | Description
object | An object expression that evaluates to an object in the Applies To list.
number | A Long value that specifies the position of the active cell.

Remarks

Use these properties to specify a cell in an MSHFlexGrid or to determine which row or column contains the current cell. Columns and rows are numbered from zero — rows are numbered from top to bottom, and columns are numbered from left to right.

Setting these properties automatically resets RowSel and ColSel, the selection becoming the current cell. Therefore, to specify a block selection, you must set Row and Col first, and then set RowSel and ColSel.

The value of the current cell, defined by the Col and Row settings, is the text contained in that cell. To modify a cell’s value without changing the selected Row and Col properties, use the TextMatrix property.


Col, Row, Text Properties (MSHFlexGrid) Example

This example puts the word "Here" into the current cell, changes the active cell to the third cell in the third row and puts the word "There" into this new active cell. To run the program, press f5, and then click the grid.

Note If you are using the MSFlexGrid, substitute "MSHFlexGrid1" with "MSFlexGrid1."

Private Sub Form1_Load ()
   MSHFlexGrid1.Rows =8
   MSHFlexGrid1.Cols =5
End Sub

Private Sub MSHFlexGrid1_Click ()
   ' Put text in current cell.
   MSHFlexGrid1.Text ="Here"
    '   Put text in third row, third column.
   MSHFlexGrid1.Col =2
   MSHFlexGrid1.Row =2
   MSHFlexGrid1.Text ="There"
End Sub


ColSel, RowSel Properties

  • ColSel — Returns or sets the start or end column for a range of cells.

  • RowSel — Returns or sets the start or end row for a range of cells.

These properties are not available at design time.

Syntax

object.ColSel [= value]
object.RowSel [= value]

Syntax for the ColSel and RowSel properties has these parts:

Part | Description
object | An object expression that evaluates to an object in the Applies To list.
value | A Long value that specifies the start or end row, or column, for a range of cells.

Remarks

You can use these properties to select a specific region of the MSHFlexGrid programmatically, or to read the dimensions of an area that the user selects into code.

The MSHFlexGrid cursor is in the cell at Row, Col. The MSHFlexGrid selection is the region between rows Row and RowSel and columns Col and ColSel. Note that RowSel may be above or below Row, and ColSel may be to the left or to the right of Col.

Whenever you set the Row and Col properties, RowSel and ColSel are automatically reset, so the cursor becomes the current selection. To select a block of cells from code, you must first set the Row and Col properties, and then set RowSel and ColSel.


ColSel Property Example

The following code returns the value of the ColSel property into the first cell of MSHFlexGrid1. This value changes as the user clicks on various selections of cell groups.

Note If you are using the MSFlexGrid, substitute "MSHFlexGrid1" with "MSFlexGrid1."

Private Sub MSHFlexGrid1_MouseUp _
(Button As Integer, Shift As Integer, x As Single, _
y As Single)
   MSHFlexGrid1.Text = MSHFlexGrid1.ColSel
End Sub


ColPos Property

Returns the distance, in twips, between the upper-left corner of the control and the upper-left corner of a specified column.

Syntax

object.ColPos(index)

The ColPos property syntax has these parts:

Part | Description
object | An object expression that evaluates to an object in the Applies To list.
index | A Long value that specifies the column.


Cols, Rows Properties (MSHFlexGrid)

  • Cols — Returns or sets the total number of columns in an MSHFlexGrid.

  • Rows — Returns or sets the total number of rows in an MSHFlexGrid. The Rows property also returns or sets the total number of columns in each band of the MSHFlexGrid.

    Note The MSFlexGrid contains no bands. If using the Rows property programmatically in the MSFlexGrid, you can only return or set the total number of columns or rows. Also, the Rows syntax, below, cannot be used in an MSFlexGrid due to the limitations of this control. If you are using MSFlexGrid, use the syntax: object.Rows [= value].

Syntax

object.Cols [= value]
object.Rows(number) [= value]

Syntax for the Cols and Rows properties has these parts:

Part | Description
object | An object expression that evaluates to an object in the Applies To list.
number A Long value that either specifies the band to get or sets the total number of columns. Optional.

Note This is not applicable to the MSFlexGrid.
value | A Long value that specifies the number of columns or rows.

Remarks

You can use these properties to expand and shrink MSHFlexGrid dynamically at run time.

The minimum number of rows and columns is 0. The maximum number is limited by the memory available on your computer.

The value of Cols must be at least one greater than the value of FixedCols, unless they are both set to zero. The value of Rows must be at least one greater than the value of FixedRows, unless they are both set to zero.

When number is not specified, it defaults to 0. Hence, when the MSHFlexGrid is not bound to a hierarchical Recordset, using 0 or not specifying number both have the same result. Note that number is an optional parameter for backward compatibility with the MSFlexGrid.


Cols, Rows Properties (MSHFlexGrid) Example

The following example places the word "Here" into the current cell, changes the active cell to the third cell in the third row, then places "There" into that cell. To run the program, press F5, then click your MSHFlexGrid.

Note If you are using the MSFlexGrid, substitute "MSHFlexGrid1" with "MSFlexGrid1."

Private Sub Form_Load ()
   MSHFlexGrid1.Rows = 8
   MSHFlexGrid1.Cols = 5
End Sub

Private Sub MsFlexGrid1_Click ()
   ' Put text in current cell.
   MSHFlexGrid1.Text = "Here"
    ' Put text in third row, third column.
   MSHFlexGrid1.Col = 2
   MSHFlexGrid1.Row = 2
   MSHFlexGrid1.Text = "There"
End Sub


ColWidth Property (MSHFlexGrid)

Returns or sets the width of the column in the specified band, in twips. This property is not available at design time.

Note When using the MSFlexGrid, this property returns or sets the width of the specified column, in twips. Also, the ColWidth syntax, below, cannot be used in an MSFlexGrid due to the limitations of this control. If you are using MSFlexGrid, use the syntax: object.ColWidth(number) [= value]

Syntax

object.ColWidth(index, number) [= value]

The ColWidth property syntax has these parts:

Part | Description
object | An object expression that evaluates to an object in the Applies To list.
index A Long value that specifies which column's width to change.

Note This is not applicable to the MSFlexGrid.
number A Long value that specifies the band that contains the column. Optional.

Note In the MSFlexGrid, this is a numeric expression that specifies the column.
value | A numeric expression that specifies the width of the specified column, in twips.

Remarks

You can use this property to set the width of any column at run time. For instructions on setting column widths at design time, see the FormatString property.

You can set ColWidth to zero to create invisible columns, or to –1 to reset the column width to its default value, which depends on the size of the current font.

When number is not specified, it defaults to 0. Hence, when the MSHFlexGrid is not bound to a hierarchical Recordset, using 0 and not specifying number both have the same result. Note that number is an optional parameter for backward compatibility with the MSFlexGrid.


ColWidth Property Example

The following code sets the value of the size of the first column. If the AllowUserResizing property is True, the value changes as the user resizes Column 1.

Note If you are using the MSFlexGrid, substitute "MSHFlexGrid1" with "MSFlexGrid1."

Sub Form1_Load()
   MSHFlexGrid1.AllowUserResizing = True
End Sub

Sub MSHFlexGrid1_MouseUp (Button As Integer, Shift As _
Integer, X As Single, Y As Single)
   MSHFlexGrid1.Text = MSHFlexGrid1.ColWidth(0)
End Sub


DataField Property (MSHFlexGrid)

Returns the name of the field bound to the specified column in the specified band. This property is read-only.

Syntax

object.DataField(number, index) [= string]

The DataField property syntax has these parts:

Part | Description
object | An object expression that evaluates to an object in the Applies To list.
number | A Long value that specifies the band that contains the column to affect.
index | A Long value that either specifies the column to get, or sets the binding field.
string | A string expression that evaluates the name of one of the fields in the Recordset object specified by the data provider.

Remarks

When number is unspecified, it defaults to 0. Hence, when the MSHFlexGrid is not bound to a hierarchical Recordset, using 0 and not specifying number both have the same result.

If the MSHFlexGrid is not bound and the number and index are valid, DataField returns an empty string.

If a Refresh is executed after the DataProvider property is changed, the Recordset object may have different fields. This may invalidate the DataField settings of the bound columns and produce a trappable error.


FillStyle Property (MSHFlexGrid)

Returns or sets a value that determines whether setting the Text property, or one of the cell formatting properties, applies the change to all selected cells within the MSHFlexGrid.

Syntax

object.FillStyle [= value]

The FillStyle property syntax has these parts:

Part | Description
object | An object expression that evaluates to an object in the Applies To list.
value | An integer or constant that specifies the fill style, as described in Settings.

Settings

The settings for value are:

Constant | Value | Description
flexFillSingle | 0 | Single. Changing Text or any of the cell properties only affects the active cell. This is the default.
flexFillRepeat | 1 | Repeat. Changing Text or any of the cell properties affects all selected cells.

Remarks

This property must be set to 1 (Repeat) whenever you want a cell change to apply to all cells within the MSHFlexGrid.


FillStyle Property (MSHFlexGrid) Example

The following code allows you to format individual cells differently.

Note If you are using the MSFlexGrid, substitute "MSHFlexGrid1" with "MSFlexGrid1."

Sub Form1_Load ()
   MSHFlexGrid1.FillStyle = 0
End Sub


ColAlignmentFixed Property

Returns or sets the alignment of data in the fixed cells of a column in an MSHFlexGrid.

Syntax

object.ColAlignmentFixed(index) [=value]

The ColAlignmentFixed property syntax has these parts:

Part | Description
object | An object expression that evaluates to an object in the Applies To list.
index | A Long value that specifies the column.
value | An integer that determines the alignment of the data in the fixed cells, as described in Settings.

Settings

The settings for value are:

Constant | Value | Description
flexAlignLeftTop | 0 | The cell content is aligned left, top.
flexAlignLeftCenter | 1 | The cell content is aligned left, center.
flexAlignLeftBottom | 2 | The cell content is aligned left, bottom.
flexAlignCenterTop | 3 | The cell content is aligned center, top.
flexAlignCenterCenter | 4 | The cell content is aligned center, center.
flexAlignCenterBottom | 5 | The cell content is aligned center, bottom.
flexAlignRightTop | 6 | The cell content is aligned right, top.
flexAlignRightCenter | 7 | The cell content is aligned right, center.
flexAlignRightBottom | 8 | The cell content is aligned right, bottom.

Remarks

You can use the FixedCols and FixedRows properties to define the cells in a column.


FixedCols, FixedRows Properties (MSHFlexGrid)

  • FixedCols — Returns or sets the total number of fixed columns within an MSHFlexGrid.

  • FixedRows — Returns or sets the total number of fixed rows within an MSHFlexGrid.

By default, MSHFlexGrid has one fixed column and one fixed row.

Syntax

object.FixedCols [= value]
object.FixedRows [= value]

Syntax for the FixedCols and FixedRows properties has these parts:

Part | Description
object | An object expression that evaluates to an object in the Applies To list.
value | A Long value that specifies the total number of fixed columns or fixed rows.

Remarks

Fixed columns and rows are constant when you scroll other columns or rows in the MSHFlexGrid. You can specify zero or multiple fixed columns rows. In addition, you can select the colors, font, gridline, and text style of the fixed columns and rows.

If the SelectionMode property is a numerical value, when you select a fixed row or fixed column at run time, all cells within that row or column are selected.

If the AllowUserResizing property is a numerical value, you can resize the fixed rows or fixed columns at run time.

Fixed columns and fixed rows are used in spreadsheet applications to display row numbers and column names or letters.


FocusRect Property

Returns or sets a value that determines whether the MSHFlexGrid should draw a focus rectangle around the current cell.

Syntax

object.FocusRect [= value]

The FocusRect property syntax has these parts:

Part | Description
object | An object expression that evaluates to an object in the Applies To list.
value | An integer or constant that specifies the focus rectangle style, as described in Settings.

Settings

The settings for value are:

Constant | Value | Description
flexFocusNone | 0 | There is no focus rectangle around the current cell.
flexFocusLight | 1 | There is a light focus rectangle around the current cell. This is the default.
flexFocusHeavy | 2 | There is a heavy focus rectangle around the current cell.

Remarks

If a focus rectangle is drawn, the current cell is painted in the background color, as in most spreadsheets and grids. Otherwise, the current cell is painted in the selection color, hence you can see which cell is selected without the focus rectangle.


Font, FontBand, FontFixed, FontHeader Properties (MSHFlexGrid)

  • Font — Returns or sets the default font, or the font for individual cells.

  • FontBand — Returns or sets the font of the text in the band.

  • FontFixed — Returns or sets the font of the text in the fixed cells.

  • FontHeader — Returns or sets the font of the text in the header.

Syntax

object.Font
object.FontBand
object.FontFixed
object.FontHeader

The object placeholder represents an object expression that evaluates to an object in the Applies To list.


FontWidth, FontWidthBand, FontWidthFixed, FontWidthHeader Properties (MSHFlexGrid)

Returns or sets the width, in points, of the font to be used for text displayed within an MSHFlexGrid, or the grid's band, fixed, or header area.

Syntax

object.FontWidth [= value]
object.FontWidthBand [= value]
object.FontWidthFixed [= value]
object.FontWidthHeader [= value]

Syntax for the FontWidth, FontWidthBand, FontWidthFixed, and FontWidthHeader properties has these parts:

Part | Description
object | An object expression that evaluates to an object in the Applies To list.
value | Single. A numeric expression that specifies the preferred point width for the current font.

Remarks

The font width is generally chosen by Windows to match the selected font height and provide a standard aspect ratio. However, the MSHFlexGrid enables you to specify fonts that are narrower or wider than the default font. This makes it possible for you to either display more information in a cell or to emphasize a cell.

When specifying a font width, Windows selects or generates a font to match your request. For best results, use TrueType fonts.

To restore the default font width, set this property to zero.

To set the font of individual cells or cell ranges, use the CellFontBold, CellFontItalic, CellFontName, CellFontSize, and CellFontWidth properties.


ForeColor, ForeColorBand, ForeColorFixed, ForeColorHeader, ForeColorSel Properties

Returns or sets the colors used to draw text on each part of the MSHFlexGrid.

Syntax

object.ForeColor [= color]
object.ForeColorBand [= color]
object.ForeColorFixed [= color]
object.ForeColorHeader [= color]
object.ForeColorSel [= color]

Syntax for the ForeColor, ForeColorBand, ForeColorFixed, ForeColorHeader, and ForeColorSel properties has these parts:

Part | Description
object | An object expression that evaluates to an object in the Applies To list.
color | A value or constant that determines the color used to paint text in the scrollable, fixed, band, or header areas of the MSHFlexGrid.

Remarks

The picture below shows the parts of the MSHFlexGrid to which the properties refer:

Use the ForeColor property to set the text color of all non-fixed cells.

Use the CellForeColor property to set the text color of individual cells.


ForeColor, ForeColorFixed, ForeColorSel Properties Example

The following example sets the ForeColorFixed and the ForeColorSel properties of the MSHFlexGrid to change to a random color each second.

Note If you are using the MSFlexGrid, substitute "MSHFlexGrid1" with "MSFlexGrid1."

Private Sub Form_Load ()
   Timer1.Interval = 500
   MSHFlexGrid1.FillStyle = 2
   MSHFlexGrid1.Text = "Color Me"
   MSHFlexGrid1.FixedCols = 1
   MSHFlexGrid1.FixedRows = 1
End Sub

Private Sub Timer1_Timer ()
   MSHFlexGrid1.ForeColorFixed = QBColor(Rnd * 15)
   MSHFlexGrid1.ForeColorSel = QBColor(Rnd * 10)
End Sub


FormatString Property

Sets the column widths, alignments, fixed row text, and fixed column text of the MSHFlexGrid.

Syntax

object.FormatString [= string]

The FormatString property syntax has these parts:

Part | Description
object | An object expression that evaluates to an object in the Applies To list.
string | A string expression for formatting text in rows and columns, as described in Remarks.

Remarks

At design time, the MSHFlexGrid parses and interprets the FormatString to obtain the following information: number of rows and columns, text for row and column headings, column width, and column alignment.

The FormatString property contains segments separated by pipe characters (|). The text between pipes defines a column and may also contain special alignment characters. These characters align the entire column to the left (<), center (^), or right (>). In addition, the text is assigned to row zero by default, and the text width defines the width of each column.

The FormatString property may contain a semicolon (;). This causes the remainder of the string to be interpreted as row heading and row width information. In addition, the text is assigned to column zero by default, and the longest string defines the width of column zero.

The MSHFlexGrid creates additional rows and columns to accommodate all fields defined by the FormatString. Additional rows and columns are not deleted if only a few fields are specified. To remove additional rows and columns, set the Rows and Cols properties.


FormatString Property Example

The following examples illustrate how the FormatString property works.

Note If you are using the MSFlexGrid, substitute "MSHFlexGrid1" with "MSFlexGrid1."

' Set column headers.
s$ = "<Region |<Product |<Employee |>Sales "
MSHFlexGrid1.FormatString = s$

' Set row headers (note semicolon at start)
s$ = ";Name|Address|Telephone|Social Security#"
MSHFlexGrid1.FormatString = s$

' Set column and row headers.
s$ = "|Name|Address|Telephone|Social Security#"
s$ = s$ + ";|Robert|Jimmy|Bonzo|John Paul"
MSHFlexGrid.FormatString = s$


GridColor, GridColorBand, GridColorFixed, GridColorHeader, GridColorIndent, GridColorUnpopulated Properties

Returns or sets the line color used between the cells, bands, headers, indents, or unpopulated areas of the MSHFlexGrid.

Note If using the MSFlexGrid, only the GridColor and GridColorFixed properties are available.

Syntax

object.GridColor [= color]
object.GridColorBand [= color]
object.GridColorFixed [= color]
object.GridColorHeader [= color]
object.GridColorIndent [= color]
object.GridColorUnpopulated [= color]

Syntax for the GridColor, GridColorBand, GridColorFixed, GridColorHeader, GridColorIndent, and GridColorUnpopulated properties has these parts:

Part | Description
object | An object expression that evaluates to an object in the Applies To list.
color | A value or constant that determines the color used to paint the gridlines in the scrollable or fixed areas of the MSFlexGrid.

Remarks

The GridColor property can only be used when the GridLines property is set to 1 (Lines).

The GridColorFixed property can only be used when GridLinesFixed is set to 1 (Lines).

Raised and inset gridlines are always drawn in black and white.


GridLines, GridLinesBand, GridLinesFixed, GridLinesHeader, GridLinesIndent, GridLinesUnpopulated Properties (MSHFlexGrid)

Returns or sets a value that determines whether lines are drawn between cells, bands, headers, indents, or unpopulated areas. These properties also determine the type of lines that are drawn in the MSHFlexGrid.

Note If using the MSFlexGrid, only the GridLines and GridLinesFixed properties are available.

Syntax

object.GridLines [= value]
object.GridLinesBand [= value]
object.GridLinesFixed [= value]
object.GridLinesHeader [= value]
object.GridLinesIndent [= value]
object.GridLinesUnpopulated [= value]

Syntax for the GridLines, GridLinesBand, GridLinesFixed, GridLinesHeader, GridLinesIndent, and GridLinesUnpopulated properties has these parts:

Part | Description
object | An object expression that evaluates to an object in the Applies To list.
value | An integer or constant that specifies the type of lines drawn, as described in Settings.

Settings

The settings for value are:

Constant | Value | Description
flexGridNone | 0 | There are no lines between cells. In the MSFlexGrid, this is the default for GridLines.
flexGridFlat | 1 | The line style between cells is set to normal, flat, lines. In the MSHFlexGrid, this is the default for GridLines.
flexGridInset | 2 | The line style between cells is set to inset lines. In the MSFlexGrid, this is the default for GridLinesFixed.
flexGridRaised | 3 | The line style between cells is set to raised lines. In the MSHFlexGrid, this is the default for GridLinesFixed.

Remarks

When the GridLines property is set to 1 (Lines), the color of the lines is determined by the GridColor property.

Raised and inset gridlines are always black and white.


GridLineWidth, GridLineWidthBand, GridLineWidthFixed, GridLineWidthHeader, GridLineWidthIndent, GridLineWidthUnpopulated Properties (MSHFlexGrid)

Returns or sets the width, in pixels, of the lines displayed between cells, bands, headers, indents, or unpopulated areas.

Note For the MSFlexGrid control, only the GridLineWidth property is available.

Syntax

object.GridLineWidth [= value]
object.GridLineWidthBand [= value]
object.GridLineWidthFixed [= value]
object.GridLineWidthHeader [= value]
object.GridLineWidthIndent [= value]
object.GridLineWidthUnpopulated [= value]

Syntax for the GridLineWidth, GridLineWidthBand, GridLineWidthFixed, GridLineWidthHeader, GridLineWidthIndent, and GridLineWidthUnpopulated properties has these parts:

Part | Description
object | An object expression that evaluates to an object in the Applies To list.
value | A numeric expression that specifies the preferred width, in pixels, for the current line.


HighLight Property (MSHFlexGrid)

Determines whether selected cells appear highlighted within the MSHFlexGrid.

Syntax

object.HighLight [= value]

The HighLight property syntax has these parts:

Part | Description
object | An object expression that evaluates to an object in the Applies To list.
value | An integer or constant that specifies when the MSHFlexGrid should highlight selected cells, as described in Settings.

Settings

The settings for value are:

Constant | Value | Description
flexHighlightNever | 0 | There is no highlight on the selected cells.
flexHighlightAlways | 1 | The selected cells are always highlighted. (Default)
flexHighlightWithFocus | 2 | The highlight appears only when the control has focus.

Remarks

When this property is set to zero and a range of cells is selected, there is no visual cue or emphasis indicating the selected cells.


LeftCol Property (MSHFlexGrid)

Returns or sets the left-most visible non fixed column in the MSHFlexGrid. This property is not available at design time.

Syntax

object.LeftCol [= value]

The LeftCol property syntax has these parts:

Part | Description
object | An object expression that evaluates to an object in the Applies To list.
value | An integer that specifies the left-most column.

Remarks

This property can be used programmatically to scroll within the MSHFlexGrid. Use the TopRow property to determine the topmost visible row of the MSHFlexGrid.


MergeCells Property

Returns or sets a value that determines whether cells with the same contents should be grouped in a single cell spanning multiple rows or columns.

Syntax

object.MergeCells [=value]

The MergeCells property syntax has these parts:

Part | Description
object | An object expression that evaluates to an object in the Applies To list.
value | An integer or constant that specifies the grouping (merging) of cells, as specified in Settings.

Settings

The settings for value are:

Constant | Value | Description
flexMergeNever | 0 | Never. The cells containing identical content are not grouped. This is the default.
flexMergeFree | 1 | Free. Cells with identical content always merge.
flexMergeRestrictRows | 2 | Restrict Rows. Only adjacent cells (to the left of the current cell) within the row containing identical content merge.
flexMergeRestrictColumns | 3 | Restrict Columns. Only adjacent cells (to the top of the current cell) within the column containing identical content merge.
flexMergeRestrictBoth | 4 | Restrict Both. Only adjacent cells within the row (to the left) or column (to the top) containing identical content merge.

Remarks

The ability to merge cells enables you to present data in a clear, concise manner. You can use cell merging in conjunction with the sorting and column order functions of the MSHFlexGrid.

To use the cell merging capabilities of the MSHFlexGrid:

  • Set MergeCells to a value other than zero. (The difference between the settings is explained in the example.)

  • Set the MergeRow and MergeCol array properties to True for the rows and columns to be merged.

When using the cell merging capabilities, the MSHFlexGrid merges cells with identical content. The merging is automatically updated whenever the cell content changes.

When MergeCells is set to a value other than 0 (Never), selection highlighting is automatically turned off. This is done to speed up repainting, and because selection of ranges containing merged cells may lead to unexpected results.


MergeCells Property Example

The following example shows the basic MergeCells property.

No Merging
MergeCells =0
MergeRow(0) =True
MergeRow(1) =True
MergeRow(2) =True
MergeRow(3) =False

This is the regular view.
Free Merging
MergeCells =1
MergeRow(0) =True
MergeRow(1) =True
MergeRow(2) =True
MergeRow(3) =False

Notice how the third employee cell (Donna) merges across products to its left and across sales to its right.
Restricted Merging
MergeCells =2
MergeRow(0) =True
MergeRow(1) =True
MergeRow(2) =True
MergeRow(3) =False

Notice how the third employee cell (Donna) no longer merges across sales.


MergeCol, MergeRow Properties

Returns or sets a value that determines which rows and columns can have their contents merged. These properties must be True to use the MergeCells property.

Syntax

object.MergeCol(number) [=Boolean]
object.MergeRow(number) [=Boolean]

Syntax for the MergeCol and MergeRows properties has these parts:

Part | Description
object | An object expression that evaluates to an object in the Applies To list.
number | A Long value that specifies the column or row in the MSHFlexGrid.
Boolean | A Boolean that specifies whether merging occurs when adjacent cells display identical content.

Settings

The settings for Boolean are:

Part | Description
True | When adjacent cells display identical content, the rows merge to the left or the columns merge to the top.
False | When adjacent cells display identical content, no cells merge. This is the default for MergeCol and MergeRow.

Remarks

If the MergeCells property is set to a nonzero value, adjacent cells with identical values are merged only if they are in a row with the MergeRow property set to True or in a column with the MergeCol property set to True.

For details on the merging functionality of the MSHFlexGrid, see the MergeCells property.


MouseCol, MouseRow Properties

Returns the current mouse position, in row and column coordinates.

Syntax

object.MouseCol [=value]
object.MouseRow [=value]

Syntax for the MouseCol and MouseRow properties has these parts:

Part | Description
object | An object expression that evaluates to an object in the Applies To list.
value | The row and column coordinates that specify the current mouse position.

Remarks

Use these properties programmatically to determine the mouse location. These properties are useful in displaying context-sensitive help for individual cells and testing whether the user has clicked on a fixed row or column.


Name Property (MSHFlexGrid)

Returns or sets the name of the aggregate field or the field by which to group.

Note This is not applicable to the MSFlexGrid.

Syntax

object.Name [=string]

The Name property syntax has these parts:

Part | Description
object | An object expression that evaluates to an object in the Applies To list.
string | A string expression that contains the name of the aggregate field or the field by which to group. For the GroupingField object, the default is the name of the first field in the current Command object. For Aggregates, the default is "Aggregate" plus a number that uniquely identifies the field.

Remarks

This property cannot have the same name as the field where the aggregate will be created. For AggregateOn with grouping, this is the name of any field in the current Command object. For AggregateOn with relation, this is the name of any field in the parent Command object.

The name of the GroupingField object must be a field name that exists in the current Command object.

The ADO Name property is used to generate the SHAPE command.


Picture Property (MSHFlexGrid)

Returns a picture of your MSHFlexGrid. This picture is suitable for printing, saving to disk, copying to the clipboard, or assigning to a different control.

Syntax

object.Picture [=picture]

The Picture property syntax has these parts:

Part | Description
object | An object expression that evaluates to an object in the Applies To list.
picture | A bitmap showing your MSHFlexGrid.

Remarks

The bitmap picture is a snapshot of your entire MSHFlexGrid on the Project Form window. It can, therefore, be very large. There are two ways to reduce the size of a bitmap picture. One option is to create a picture of a section of your MSHFlexGrid. To do this, write a routine to hide all elements you don’t want to show, acquire the picture, and then restore the MSHFlexGrid.

Alternatively, you can set the PictureType property to 1 (Monochrome). However, this decreases not only the amount of memory used, but also the picture resolution.


ColData, RowData, Picture Properties Example

The following code shows how you can trap out-of-memory errors and automatically switch to monochrome mode using the PictureType property. In addition, it shows how to create a picture within the MSHFlexGrid that includes only the current selection.

Note If you are using the MSFlexGrid, substitute "MSHFlexGrid1" with "MSFlexGrid1."

Sub CopySelectedPictureToClipboard (myFlex As _
MSHFlexGrid)
   Dim i As Integer, tr As Long, lc As Long, _
   hl As Integer
   ' Get ready to operate.
   MyFlex.Redraw =False   ' To eliminate flicker.
   hl =MyFlex.HighLight   ' Save current settings.
   tr =MyFlex.TopRow
   lc =MyFlex.LeftCol
   MyFlex.HighLight =0   ' No highlight on picture.
   ' Hide nonselected rows and columns.
   ' (Save original sizes in RowData/ColData
   ' properties.)
   For i =MyFlex.FixedRows To MyFlex.Rows - 1
      If i < MyFlex.Row Or i > MyFlex.RowSel Then
         MyFlex.RowData(i) =MyFlex.RowHeight(i)
         MyFlex.RowHeight(i) =0
      End If
   Next
   For i =MyFlex.FixedCols To MyFlex.Cols - 1
      If i < MyFlex.Col Or i > MyFlex.ColSel Then
         MyFlex.ColData(i) =MyFlex.ColWidth(i)
         MyFlex.ColWidth(i) =0
      End If
   Next
   ' Scroll to top left corner.
   MyFlex.TopRow =MyFlex.FixedRows
   MyFlex.LeftCol =MyFlex.FixedCols
   ' Copy picture.
   clipboard.Clear
   On Error Resume Next
   MyFlex.PictureType =0 ' Color.
   clipboard.SetData MyFlex.Picture
   If Error <> 0 Then
      MyFlex.PictureType =1 ' Monochrome.
      clipboard.SetData MyFlex.Picture
   Endif
   ' Restore control.
   For i =MyFlex.FixedRows To MyFlex.Rows - 1
      If i < MyFlex.Row Or i > MyFlex.RowSel Then
         MyFlex.RowHeight(i) =MyFlex.RowData(i)
      End If
   Next
   For i =MyFlex.FixedCols To MyFlex.Cols - 1
      If i < MyFlex.Col Or i > MyFlex.ColSel Then
         MyFlex.ColWidth(i) =MyFlex.ColData(i)
      End If
   Next
   MyFlex.TopRow =tr
   MyFlex.LeftCol =lc
   MyFlex.HighLight =hl
   MyFlex.Redraw =True
End Sub

The following example shows how to set the MSHFlexGrid's Picture property to a PictureBox control:

Note If you are using the MSFlexGrid, substitute "MSHFlexGrid1" with "MSFlexGrid1."

Private Sub Form_Click ()
   Set Picture1.Picture =MSHFlexGrid1.Picture
End Sub


PictureType Property

Returns or sets the type of picture to be generated by the Picture property.

Syntax

object.PictureType [=type]

The PictureType property syntax has these parts:

Part | Description
object | An object expression that evaluates to an object in the Applies To list.
type | An integer or constant that specifies the type of picture that should be generated, as described in Settings.

Settings

The settings for type are:

Constant | Value | Description
flexPictureColor | 0 | This produces a high-quality full-color image.
flexPictureMonochrome | 1 | This produces a lower-quality, monochrome, image that consumes less memory.


Redraw Property

Returns or sets a value that determines whether the MSHFlexGrid should be automatically redrawn after each change.

Syntax

object.Redraw [=Boolean]

The Redraw property syntax has these parts:

Part | Description
object | An object expression that evaluates to an object in the Applies To list.
Boolean | A Boolean expression that specifies whether the MSHFlexGrid is automatically redrawn after each change.

Settings

The settings for Boolean are:

Part | Description
True | The MSHFlexGrid automatically redraws after each change. This is the default.
False | The MSHFlexGrid doesn’t redraw after each change.

Remarks

You can use this property in code to reduce flicker while making extensive updates to the contents of the MSHFlexGrid.


Redraw Property Example

The following code turns off redrawing, makes several changes to the contents of MSHFlexGrid, and then turns on redrawing to show the results.

Note If you are using the MSFlexGrid, substitute "MSHFlexGrid1" with "MSFlexGrid1."

Dim i As Integer
' Freeze MSHFlexGrid to avoid flicker.
MSHFlexGrid.Redraw =False
' Update MSHFlexGrid contents.
For i =MSHFlexGrid1.FixedRows To MSHFlexGrid1.Rows - 1
MSHFlexGrid1.TextMatrix(i, 1) =GetName(i, 1)
MSHFlexGrid1.TextMatrix(i, 2) =GetName(i, 2)
Next
' Show results.
MSHFlexGrid1.Redraw =True


RowExpandable, RowExpanded Properties (MSHFlexGrid)

Specify whether the current row is expanded or collapsed. The current row is defined by the Col and Row properties.

The RowExpandable property is not available at design time.

Syntax

object.RowExpandable [=Boolean]
object.RowExpanded [=Boolean]

The syntax for the RowExpandable and Row Expanded properties has these parts:

Part | Description
object | An object expression that evaluates to an object in the Applies To list.
Boolean | A Boolean expression that specifies whether the current row is expandable or is currently expanded.

Settings

The settings for Boolean are:

Part | Description
True | The current row is expandable.
False | The current row is collapsed and is not expandable.


RowHeightMin Property

Returns or sets the minimum row height for the entire control, in twips.

Syntax

object.RowHeightMin [=value]

The RowHeightMin property syntax has these parts:

Part | Description
object | An object expression that evaluates to an object in the Applies To list.
value | A single numeric expression that specifies the minimum row height for the MSHFlexGrid.

Remarks

Use this property if you are using small fonts but want the rows to be tall. Setting this property is easier than setting individual row heights using the RowHeight property.

The RowHeight property is independent of the form’s scale mode.


RowHeight Property (MSHFlexGrid)

Returns or sets the height of the specified row, in twips. This property is not available at design time.

Syntax

object.RowHeight(number) [=value]

The RowHeight property syntax has these parts:

Part | Description
object | An object expression that evaluates to an object in the Applies To list.
number | An integer that sets the number of the row in the MSHFlexGrid, or -1 to set all rows at once.
value | A single numeric expression that specifies the height of the row, in twips.

Remarks

You can set RowHeight to zero to create invisible rows, or to –1 to reset the row height to its default value. The default row height varies according to the current font size.

The RowHeight property is independent of the form’s scale mode.


RowIsVisible Property

Returns or sets a value that determines whether a specified row is visible.

Syntax

object.RowIsVisible(index) [=Boolean]

The RowIsVisible property syntax has these parts:

Part | Description
object | An object expression that evaluates to an object in the Applies To list.
index | A Long value that specifies the column.
Boolean | A Boolean expression that determines whether a specified row is currently visible.

Settings

The settings for Boolean are:

Setting | Description
True | The specified row is currently visible. This is the default.
False | The specified row is not currently visible.


RowPos Property

Returns the distance, in twips, between the upper-left corner of the MSHFlexGrid and the upper-left corner of a specified row.

Syntax

object.RowPos(index)

The RowPos property syntax has these parts:

Part | Description
object | An object expression that evaluates to an object in the Applies To list.
index | A Long value that specifies the column.


RowSizingMode Property (MSHFlexGrid)

Returns or sets a value that describes the sizing mode of the rows in the MSHFlexGrid.

Syntax

object.RowSizingMode [=value]

The RowSizing property syntax has these parts:

Part | Description
object | An object expression that evaluates to an object in the Applies To list.
value | An integer or constant that specifies the settings of the row size, as described in Settings.

Settings

The settings for value are:

Constant | Value | Description
flexRowSizeIndividual | 0 | Resizing a row changes only the height of that row. This is the default.
flexRowSizeAll | 1 | Resizing a row changes the height of all rows in the MSHFlexGrid.

Remarks

This property is only used when AllowUserResize is set to Rows or Both.


ScrollBars Property (MSHFlexGrid)

Returns or sets a value that determines whether an MSHFlexGrid has horizontal and/or vertical scroll bars.

Syntax

object.ScrollBars [=value]

The ScrollBars property syntax has these parts:

Part | Description
object | An object expression that evaluates to an object in the Applies To list.
value | An integer or constant that specifies the type of scroll bars, as described in Settings.

Settings

The settings for value are:

Constant | Value | Description
flexScrollNone | 0 | The MSHFlexGrid has no scroll bars.
flexScrollHorizontal | 1 | The MSHFlexGrid has a horizontal scroll bar.
flexScrollVertical | 2 | The MSHFlexGrid has a vertical scroll bar.
flexScrollBoth | 3 | The MSHFlexGrid has horizontal and vertical scroll bars. (Default)

Remarks

Scroll bars appear on an MSHFlexGrid only if its contents extend beyond its borders and value specifies scroll bars. If the ScrollBars property is set to None, the MSHFlexGrid will not have scroll bars, regardless of its contents.

Note If the MSHFlexGrid has no scroll bars in either direction, it will not allow any scrolling in that direction, even if the user uses the keyboard to select a cell that is beyond the visible area of the control.


ScrollTrack Property

Returns or sets a value that determines whether the MSHFlexGrid should scroll its contents while the user moves the scroll box along the scroll bars.

Syntax

object.ScrollTrack [=Boolean]

The ScrollTrack property syntax has these parts:

Part | Description
object | An object expression that evaluates to an object in the Applies To list.
Boolean | A Boolean expression that specifies whether the MSHFlexGrid should scroll its contents when the user moves the scroll box along the scroll bar.

Settings

The settings for Boolean are:

Part | Description
True | The MSHFlexGrid scrolls its contents while the user moves the scroll box along the scroll bar.
False | The MSHFlexGrid content only changes once the scroll box is released. This is the default.

Remarks

Set this property to False to avoid excessive scrolling and flickering. Only set it to True to emulate other controls that have this behavior or to view rows and columns as they are being scrolled.


SelectionMode Property

Returns or sets a value that determines whether an MSHFlexGrid should allow regular cell selection, selection by rows, or selection by columns.

Syntax

object.SelectionMode [=value]

The SelectionMode property syntax has these parts:

Part | Description
object | An object expression that evaluates to an object in the Applies To list.
value | An integer or constant that specifies the selection mode, as described in Settings.

Settings

The settings for value are:

Constant | Value | Description
flexSelectionFree | 0 | Free. This allows individual cells in the MSHFlexGrid to be selected, spreadsheet style. This is the default.
flexSelectionByRow | 1 | By Row. This forces selections to span entire rows, as in a multi-column list box or record-based display.
flexSelectionByColumn | 2 | By Column. This forces selections to span entire columns, as if selecting ranges for a chart or fields for sorting.


Sort Property (MSHFlexGrid)

Sets a value that sorts selected rows according to selected criteria. This property is not available at design time.

Syntax

object.Sort [=value]

The Sort property syntax has these parts:

Part | Description
object | An object expression that evaluates to an object in the Applies To list.
value | An integer or constant that specifies the type of sorting, as described in Settings.

Settings

The settings for value are:

Constant | Value | Description
flexSortNone | 0 | None. No sorting is performed.
flexSortGenericAscending | 1 | Generic Ascending. An ascending sort, which estimates whether text is string or number, is performed.
flexSortGenericDescending | 2 | Generic Descending. A descending sort, which estimates whether text is string or number, is performed.
flexSortNumericAscending | 3 | Numeric Ascending. An ascending sort, which converts strings to numbers, is performed.
flexSortNumericDescending | 4 | Numeric Descending. A descending sort, which converts strings to numbers, is performed.
flexSortStringNoCaseAsending | 5 | String Ascending. An ascending sort using case-insensitive string comparison is performed.
flexSortNoCaseDescending | 6 | String Descending. A descending sort using case-insensitive string comparison is performed.
flexSortStringAscending | 7 | String Ascending. An ascending sort using case-sensitive string comparison is performed.
flexSortStringDescending | 8 | String Descending. A descending sort using case-sensitive string comparison is performed.
flexSortCustom | 9 | Custom. This uses the Compare event to compare rows.

Remarks

The Sort property always sorts entire rows. To specify the range to be sorted, set the Row and RowSel properties. If Row and RowSel are the same, the MSHFlexGrid will sort all non-fixed rows.

The keys used for sorting are determined by the Col and ColSel properties. Sorting is always done in a left-to-right direction. For example, if Col =3 and ColSel =1, the sort is done according to the contents of columns 1, then 2, then 3.

The method used to compare the rows is determined by the value, as explained in Settings. The 9 (Custom) setting is the most flexible, but is slower than the other settings, typically by a factor of ten. An alternative to using this setting is to create an invisible column, fill it with the keys, and then perform a sort based on Custom using another setting. This is a good approach for sorts that are based on dates.


Sort, TextMatrix Properties (MSHFlexGrid) Example

The following example uses the Sort and TextMatrix properties. It performs an MSHFlexGrid sort according to the value of a ComboBox control. To use the example, place an MSHFlexGrid control and a ComboBox control on a form. Paste the following code into the Declarations section, and then press f5.

Note If you are using the MSFlexGrid, substitute "MSHFlexGrid1" with "MSFlexGrid1."

Private Sub Combo1_Click()
' Select Column according to Sort method.
Select Case Combo1.ListIndex
Case 0 To 2
MSHFlexGrid1.Col =1
Case 3 To 4
MSHFlexGrid1.Col =2
Case 4 To 8
MSHFlexGrid1.Col =1
End Select
' Sort according to Combo1.ListIndex.
MSHFlexGrid1.Sort =Combo1.ListIndex
End Sub
Private Sub Form_Load()
Dim i As Integer
' Fill MSHFlexGrid with random data.
MSHFlexGrid1.Cols =3 ' Create three columns.

For i =1 To 11 ' Add ten items.
MSHFlexGrid1.AddItem ""
MSHFlexGrid1.Col =2
MSHFlexGrid1.TextMatrix(i, 1) =SomeName(i)
MSHFlexGrid1.TextMatrix(i, 2) =Rnd()
Next i
' Fill combo box with Sort choices
With Combo1
.AddItem "flexSortNone" ' 0
.AddItem "flexSortGenericAscending" '1
.AddItem "flexSortGenericDescending" '2
.AddItem "flexSortNumericAscending" '3
.AddItem "flexSortNumericDescending" '4
.AddItem "flexSortStringNoCaseAsending" '5
.AddItem "flexSortNoCaseDescending" '6
.AddItem "flexSortStringAscending" '7
.AddItem "flexSortStringDescending" '8
.ListIndex =0
End With
End Sub
Private Function SomeName(i As Integer) As String
Select Case i
Case 1
SomeName ="Ann"
Case 2
SomeName ="Glenn"
Case 3
SomeName ="Sid"
Case 4
SomeName ="Anton"
Case 5
SomeName ="Hoagie"
Case 6
SomeName ="Traut 'Trane"
Case 7
SomeName ="MereD Wah"
Case 8
SomeName ="Kemp"
Case 9
SomeName ="Sandy"
Case 10
SomeName ="Lien"
Case 11
SomeName ="Randy"
End Select
End Function


TextArray Property

Returns or sets the text content of an arbitrary cell.

Syntax

object.TextArray(cellindex) [=string]

The TextArray property syntax has these parts:

Part | Description
object | An object expression that evaluates to an object in the Applies To list.
cellindex | Integer. A numeric expression that specifies which cell to read or write. See Remarks.
string | A string expression containing the contents of an arbitrary cell.

Remarks

This property allows you to set or retrieve the contents of a cell without changing the Row and Col properties.

The cellindex argument determines which cell to use. It is calculated by multiplying the preferred row by the Cols property and adding the preferred column. The clearest and most convenient way to calculate cellindex is to define a function to do it, as shown in Example.


TextArray Property Example

The following example shows how to calculate cellindex by defining a function.

Note If you are using the MSFlexGrid, substitute "MSHFlexGrid1" with "MSFlexGrid1."

' Calculate index for use with TextArray property.
Function faIndex(row As Integer, col As Integer) As Long
faIndex =row * MSHFlexGrid1.Cols + col
End Function
Sub Form_Load()
Dim i as Integer
' Fill MSHFlexGrid with data using TextArray property.
For i =MSHFlexGrid1.FixedRows to MSFlexGrid1.Rows - 1
' ** column 1
MSHFlexGrid1.TextArray(faIndex(i, 1)) =RandomName()
' Column 2.
MSHFlexGrid1.TextArray(faIndex(i, 2)) =RandomNumber()
Next


Text Property (MSHFlexGrid)

Returns or sets the text content of a cell or range of cells.

Syntax

object.Text [=string]

The Text property syntax has these parts:

Part | Description
object | An object expression that evaluates to an object in the Applies To list.
string | A string expression containing the text from a cell or range of cells.

Remarks

When retrieving, the Text property always retrieves the contents of the current cell as defined by the Row and Col properties.

When setting, the Text property sets the contents of the current cell or selection depending on the setting of the FillStyle property.


TextMatrix Property

Returns or sets the text contents of an arbitrary cell.

Syntax

object.TextMatrix(rowindex, colindex) [=string]

The TextMatrix property syntax has these parts:

Part | Description
object | An object expression that evaluates to an object in the Applies To list.
rowindex, colindex | Integer. A numeric expression that specifies which cell to read or write.
string | A string expression containing the contents of an arbitrary cell.

Remarks

This property allows you to set or retrieve the contents of a cell without changing the Row and Col properties.


TextStyle, TextStyleFixed, TextStyleBand, TextStyleHeader Properties (MSHFlexGrid)

TextStyle, TextStyleBand, TextStyleFixed, TextStyleHeader Properties (MSHFlexGrid)

Returns or sets the three-dimensional style for text within a specific cell or range of cells.

  • TextStyle — determines the style of regular MSHFlexGrid cells.

  • TextStyleBand — determines the style of bands.

  • TextStyleFixed — determines the style of fixed rows and columns.

  • TextStyleHeader — determines the style of headers.

Syntax

object.TextStyle [=style]
object.TextStyleBand [=style]
object.TextStyleFixed [=style]
object.TextStyleHeader [=style]

Syntax for the TextStyle, TextStyleBand, TextStyleFixed, and TextStyleHeader properties has these parts:

Part | Description
object | An object expression that evaluates to an object in the Applies To list.
style | An integer or constant that specifies the text style, as described in Settings.

Settings

The settings for style are:

Constant | Value | Description
flexTextFlat | 0 | The text is normal, flat text. This is the default.
flexTextRaised | 1 | The text appears raised.
flexTextInset | 2 | The text appears inset.
flexTextRaisedLight | 3 | The text appears slightly raised.
flexTextInsetLight | 4 | The text appears slightly inset.

Remarks

Settings 1 and 2 work best for large and bold fonts. Settings 3 and 4 work best for small, regular fonts.


TopRow Property (MSHFlexGrid)

Returns or sets the uppermost visible row (other than a fixed row) in the MSHFlexGrid. This property is not available at design time.

Syntax

object.TopRow [=number]

The TopRow property syntax has these parts:

Part | Description
object | An object expression that evaluates to an object in the Applies To list.
number | A Long value that specifies the uppermost row in the MSHFlexGrid.

Remarks

You can use this property to programmatically read or set the visible top row of the MSHFlexGrid. Use the LeftCol property to determine the leftmost visible column in the MSHFlexGrid.

The largest row number that you can use when setting TopRow is the total number of rows minus the number of rows that are visible in the MSHFlexGrid. If this property is set to a greater row number, the MSHFlexGrid will reset it to this largest possible value.


Version Property (MSHFlexGrid)

Returns the version of the MSHFlexGrid that is currently loaded in memory.

Syntax

object.Version [=integer]

The Version property syntax has these parts:

Part | Description
object | An object expression that evaluates to an object in the Applies To list.
integer | An integer representing the version number of the MSHFlexGrid.

Remarks

The version number is a three-digit integer. The first digit represents the major version number and the last two digits represent the minor version number. For example, version 3.5 returns an integer of 350.


WordWrap Property (MSHFlexGrid)

Returns or sets a value that determines whether a cell displays multiple lines of text or one long line of text.

Note Return characters, such as Chr(13), also force line breaks.

Syntax

object.WordWrap [=Boolean]

The WordWrap property syntax has these parts:

Part | Description
object | An object expression that evaluates to an object in the Applies To list.
Boolean | A Boolean expression that specifies whether the text within a cell wraps.

Settings

The settings for Boolean are:

Part | Description
True | The cell text displays with multiple, wrapping lines of text.
False | The cell text displays as one long line of text. This is the default.

Remarks

The MSHFlexGrid displays text slightly faster when WordWrap is set to False.