Cell Property

Returns or sets cell properties for an arbitrary range.

Syntax

[form!]vsFlexGrid.Cell(Setting As CellPropertySettings, [R1 As Long], [C1 As Long], [R2 As Long], [C2 As Long]) [ = Value ]

Remarks

The Cell property allows you to read or set cell properties directly to individual cells or ranges (without selecting them).

The parameters for the Cell property are described below:

Setting As CellPropertySettings

This parameter determines which property will be read or set. The settings available are listed below.

Row1, Col1, Row2, and Col2 As Long  (optional)

When reading cell properties, only cell (Row1, Col1) is used. When setting, the whole range is affected. The only exception is when you read the flexcpText property of a range. In this case, a clip string is returned containing the text in the whole selection. The default value for Row1 and Col1 is the current row and the current column (Row and Col properties). Thus, if they are not supplied, the current cell is used. The default value for Row2 and Col2 is Row1 and Col1. Thus, if they are not supplied, a single cell is used.

Valid settings for the Setting parameter are:

 

Constant

Value

Description

FlexcpText

0

Returns or sets the cell's text (or clip string for selections).

FlexcpTextStyle

1

Returns or sets the cell's text style (see the CellTextStyle property).

FlexcpAlignment

2

Returns or sets the cell's text alignment (see the CellAlignment property).

FlexcpPicture

3

Returns or sets the cell's picture (see the CellPicture property).

FlexcpPictureAlignment

4

Returns or sets the cell's picture alignment (see the CellPictureAlignment property).

FlexcpChecked

5

Returns or sets the state of the cell's check box (see the CellChecked property).

FlexcpBackColor

6

Returns or sets the cell's back color (see the CellBackColor property).

FlexcpForeColor

7

Returns or sets the cell's fore color (see the CellForeColor property).

flexcpFloodPercent

8

Returns or sets the cell's flood percent (see CellFloodPercent property).

flexcpFloodColor

9

Returns or sets the cell's flood color (see the CellFloodColor property).

flexcpFont

10

Returns or sets the cell's font.

flexcpFont*

11-17

Returns or sets properties of the cell's font (see the CellFontName property, and so on).

flexcpValue

18

Returns the value of the cell's text (read-only).

flexcpTextDisplay

19

Returns the cell's formatted text (read only).

flexcpData

20

Returns or sets a Variant attached to the cell.

flexcpCustomFormat

21

Returns True if the cell has custom formatting (set to False to remove all custom formatting).

FlexcpLeft

22

Returns a cell's left coordinate, in twips, taking merging into account (read-only).

FlexcpTop

23

Returns a cell's top coordinate, in twips, taking merging into account (read-only).

FlexcpWidth

24

Returns a cell's width, in twips, taking merging into account (read-only).

FlexcpHeight

25

Returns a cell's height, in twips, taking merging into account (read-only).

flexcpVariantValue

26

Returns a double if the cell contains a numeric value or a string otherwise (read-only).

flexcpRefresh

27

Set to True to force a cell or range to be repainted.

FlexcpSort

28

Allows you to sort a range without changing the selection.

 

Most of the settings listed above can also be read or set through other properties (for example, Text, TextArray, and so on). Using the Cell property is often more convenient, however, because you it lets you specify the cell range.

A couple of settings are not accessible through other properties and deserve additional comments:

flexcpTextDisplay

This setting allows you to get the formatted contents of the cell, as it is displayed to the user. For example, if a cell contains the string "1234" and the ColFormat property is set to "#,###.00", this setting will return "1,234.00".

flexcpData

This settings allows you to attach custom information to individual cells, the same way the RowData and ColData properties allow you to attach custom information to rows and columns. These values are Variants, which means you may associate virtually any type of data with a cell, including strings, longs, objects, arrays, and so on.

flexcpFont

This setting allows you to assign fonts to cells in one step. This is much more efficient than setting each font property individually. For example, instead of writing:

    fg.CellFontName = "Arial"

    fg.CellFontSize = 8

    fg.CellFontBold = True

you may write

    fg.Cell(flexcpFont) = Text1.Font

flexcpCustomFormat
This setting returns a Boolean value that indicates whether a cell has any custom formatting associated with it (for example, back color, font, data, and so on). You may also set this to False to clear any custom formatting a cell may have.

For example:

    ' set the font to bold on cell (1,1)

    fg.Cell(flexcpFontBold, 1, 1) = True

    ' set the font to bold on cells (1,1)-(10,1)

    fg.Cell(flexcpFontBold, 1, 1, 10) = True

Data Type

Variant

See Also

VSFlexGrid Control