FindRow Property

Returns the index of a row that contains a specified string or RowData value.

Syntax

val& = [form!]VSFlexGrid.FindRow(Item As Variant, [ Row As Long ], [ Col As Long ], [ CaseSensitive As Boolean ], [ FullMatch As Boolean])

Remarks

The FindRow method allows you to look up rows based on cell contents or RowData values. The search is much faster and easier to implement than a Visual Basic loop.

The parameters for the FindRow property are described below:

Item As Variant

This parameter contains the data being searched.

Row As Long (optional)

This parameter contains the rows where the search should start. The default value is FixedRows.

Col As Long (optional)

This parameter tells the control which column should be searched. By default, this value is set to -1, which means the control will look for matches against RowData. If Col is set to a value greater than -1, then the control will look for matches against the cell's contents for the given column.

CaseSensitive As Boolean (optional)

This parameter is True by default, which means the search is case-sensitive. Set it to False if you want a case-insensitive search (for example, when looking for "CELL" you may find "cell" ). This parameter is only relevant when you are looking for a string.

FullMatch As Boolean (optional)

This parameter is True by default, which means the search is for a full match. Set it to False if you want to allow partial matches (for example, when looking for "MY" you may find "MYCELL"). This parameter is only relevant when you are looking for a string.

FindRow returns the index of the row where the data was found, or -1 if the data was not found.

The code below shows how this method is used:

    ' assign some data to row 40 and cell (40, 5)

    fg.RowData(30) = "MyRow"

    fg.TextMatrix(40, 5) = "MyCell"

    Debug.Print fg.FindRow("MyRow")        ' find a row by its RowData

    > 30

    Debug.Print fg.FindRow("MyCell")       ' no rows have RowData = "MyCell"

    > -1

    Debug.Print fg.FindRow("MyCell", , 5)  ' look for text in column 5

    > 40

    Debug.Print fg.FindRow("MYCELL", , 5)         ' case-sensitive search fails

    > -1

    Debug.Print fg.FindRow("MYCELL", , 5, False)  ' case-insensitive search succeeds

    > 40

    Debug.Print fg.FindRow("My", , 5)             ' full-match search fails

    > -1

    Debug.Print fg.FindRow("My", , 5, , False)    ' partial-match search succeeds

    > 40

Note

The FindRow method is useful for searching rows through code. To allow users to perform incremental searches by typing into cells, use the AutoSearch property instead.

Data Type

Long

See Also

VSFlexGrid Control