VB6 MSFlexGrid - Unable to set columns and rows count at runtime

1.6k Views Asked by At

I have a Visual Basic 6 form with a MSFlexGrid control inside, which takes data from a record set(ADODB) and displays them.

Before starting the copy of data to the FlexGrid, I'm trying to set the rows count, depending on records count. Also I have a collection which contains columns' names, then I can get the number of columns from here.

The following is a code snippet:

v_colsCount = UBound(aCols) + 2 // aCols = array with columns' names

v_regCount = rs.RecordCount // rs = my ADODB record set

myFlexGrid.Rows = 0 // for cleaning rows from a previous display

myFlexGrid.Rows = IIf(v_regCount > 0, v_regCount + 1, 2)

myFlexGrid.Cols = v_colsCount

myFlexGrid.FixedRows = 1
myFlexGrid.FixedCols = 0

There are 7532 rows and 52 columns. The problem comes when I run the application and try to execute this part of the code (fill the FlexGrid with data from the record set):

For iRow = 1 To v_regCount
    For iCol = 0 To v_colsCount -2
        sAux = ConvStr(rs.Fields(aCols(iCol)).Value)
        myFlexGrid.TextMatrix(iRow, iCol) = sAux

I notice that

v_regCount = 7532 but v_colsCount = 2 ,

and I get an error ("Substring out of range"). If I swap the settings order (i.e. if I set myFlexGrid.Cols after set myFlexGrid.Rows), then

v_regCount = 0 and v_colsCount = 52

I don't understand why I can't set rows and columns count at the same time.

Any ideas? Thanks in advance

0

There are 0 best solutions below