TMSFMXGrid OnCellBeforeDraw slows down


I am using a TMSFMXGrid on a small database.  I want to concatenate several fields into a single column so I tried to use a custom draw event (C++ code)

void __fastcall TBrowseData::TMSFMXGrid1CellBeforeDraw(TObject *Sender, int ACol,
          int ARow, TCanvas *ACanvas, TRectF &ARect, TRectF &ATextRect, bool &ADrawText,
          bool &ADrawBackGround, bool &AllowDraw)
      if (ACol == 1 && ARow >= TMSFMXGrid1->FixedRows) {
                  // concatentate the data from columns 8,9,10 into the column 1 
                 TMSFMXGrid1->Cells[1][ARow] = TMSFMXGrid1->Cells[8][ARow] + "-" +
                                      TMSFMXGrid1->Cells[9][ARow] + "-" +
                                      TMSFMXGrid1->Cells[10][ARow] ;

This seems to really make the grid run very slowly. 

Can you suggest a better way to combine data from different database fields?


Dear Mr. Aitkin, 

It is normal that the grid is slow when modifying grid data inside a draw event.
The OnCellBeforeDraw is called when a cell is repainted.

Please use the OnGetCellData event to merge multiple cell data.

Kind Regards, 
Scheldeman Pieter

Pieter Scheldeman2013-01-16 09:15:40

Hi Pieter

Thanks for the tip - using the Event OnGetCellData is certainly faster.

However - the data in the column is not always painted corrected.

1) Grid initial display - (the column still shows original data, only if I resize window is it updated)
2) Navigator - scroll to bottom (the last record data set is not painted correctly)
3) Navigator - scroll to top (the first record in data set is not painted correctly)
4) Page down - only the record at the top of screen is correct

Are there additional re-paint commands that need to be called ?


Can you perhaps send us a sample that we can investigate here?

If you modify the Cells data collection then you need to perform this at start-up.
The OnGetCellData needs to be used in combination with the var CellString parameter.

Setting a Cell data in the OnGetCellData event could lead to strange values as you are experiencing.

Kind Regards, 
Scheldeman Pieter