OnDrawCell (C++)

From RAD Studio Code Examples
Jump to: navigation, search


The following code uses the bitmaps in an image list component to draw the contents of each cell in a draw grid. It draws a focus rectangle around the cell that has focus. goDrawFocusSelect in the DrawGrid Options parameter must be True to set focus on a cell. The ImageList Draw method must be called after DrawFocusRect. The OnSelectCell event handler must be implemented to return True.


void __fastcall TForm1::DrawGrid1DrawCell(
  TObject *Sender, int ACol, int ARow, TRect &Rect, TGridDrawState State)
  long index = ARow * DrawGrid1->ColCount + ACol;
  DrawGrid1->Canvas->Brush->Color = clBackground;
  if (State.Contains(gdFocused))
	Label1->Caption = "Cell " + IntToStr(int(index)) + " has the focus.";
	DrawGrid1->Canvas, Rect.Left, Rect.Top, index, True);

void __fastcall TForm1::DrawGrid1SelectCell(TObject *Sender, int ACol, int ARow,
      bool &CanSelect)
  CanSelect= True;