Showing Multiple Lines in a Cell TTMSFNCGrid

Using a TMSFNCGrid (version in Delphi Athens in a VCL application. I'm trying to draw multiple lines of text in a cell by parsing the text assigned to the cell. Each row in the grid may be a different height depending on how many lines are in a cell. Text in the cell may be different colors as well. (Entries in the grid represent who took time off from work on that day - the grid shows then entire month.)

Here is the code I've tried, but it does not seem to draw the text in separate lines:

procedure TfrmMonthCalendar.grdCalendarCellBeforeDraw(Sender: TObject; ACol,
  ARow: Integer; AGraphics: TTMSFNCGraphics; var ARect, ATextRect: TRectF;
  var ADrawText, ADrawBackGround, ADrawBorder, AllowDraw: Boolean);
  EntryList: string;
  X1, X2, Y1, Y2: integer;
  idx: integer;
//  TmpRect,
  Rect: TRect;
  TextWide: integer;
  if ARow = 0 then
  if grdRecList.Cells[ACol,ARow] = '' then
  Rect := TRect.Create(Trunc(ATextRect.Left), Trunc(ATextRect.Top),
        Trunc(ATextRect.Right), Trunc(ATextRect.Bottom));

  ADrawText := False;
  EntryList := grdRecList.Cells[ACol,ARow];
  idx := pos('|',EntryList);
  ctr := 0;
  while idx > 0 do begin
    Entry := copy(EntryList,1,idx-1);
    if ctr = 0 then begin
      AGraphics.Canvas.Font.Style := [TFontStyle.fsBold];
      AGraphics.Canvas.Font.Color := clBlack;
    else begin
      AGraphics.Canvas.Font.Style := {};
      AGraphics.Canvas.Font.Color := TIDRecClass(fGridRecs[ACol,ARow][ctr]).IDNum;
    AGraphics.DrawText(Rect, Entry);
    EntryList := copy(EntryList,idx+1,length(EntryList));
    Rect.Top := Rect.Top + PixelAdj(13);
    idx := pos('|',EntryList);
  if grdRecList.RowHeights[ARow] < Rect.Top then
    grdRecList.RowHeights[ARow] := Rect.Top;

I've also attached an image of what I'm trying to accomplish if my description isn't clear enough.

To add multiple lines you can just include HTML in your cell text: <font color="gcRed">Line 1</font><BR><font color="gcGreen">Line 2</font>

Using HTML was the solution I was looking for. However, I have another problem. Once I have loaded the cells of the grid with the lines to be displayed, the rows of the grid do not resize automatically. I created a routine to set the RowHeight values for each row properly after adding the data, but it does not seem to take effect until I either click on the grid or resize the form. How can I resize the rows automatically without requiring the user to do something to the form? I've tried the Repaint method and the Invalidate method but neither one seems to work.

You can use AutoSizeRow / AutoSizeRows, or set RowHeights property, but please encapsulate it in BeginUpdate / EndUpdate to make sure it properly recalculates.

This will slow the solution

Thanks. That did the trick. I'm not loading so much data that I can see any slowdown.

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.