0

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

  • Can you put the declaration of "aCols" and how are you filling this array – Beldi Anouar May 05 '16 at 15:41
  • I just realized that an error is generated after executing the line: `myFlexGrid.Cols = v_colsCount`. Error description says _Unable to Allocate Memory for FlexGrid_ . I think that's why I can't set FlexGrid.Cols as 52, so FlexGrid.Cols keeps with its default value (2). – Laura Vélez May 05 '16 at 15:56
  • Is it possible you might do better to use a *DataGrid* objects as opposed to *FlexGrid*? – CMaster May 10 '16 at 12:32
  • I think use _DataGrid_ instead of _FlexGrid_ is a good idea, but I can't do this... I have to work with the existing objects because they are shared among several projects. Anyway, thank you! – Laura Vélez May 10 '16 at 18:41
  • I solved the problem by changing the SQL query that fills my RecordSet. – Laura Vélez May 10 '16 at 18:44
  • Then, the number of records is greatly reduced and I can show in the FlexGrid only the information I need to display. – Laura Vélez May 10 '16 at 18:52

0 Answers0