Back to Devexpress

TcxCustomGridTableView.OnCustomDrawPartBackground Event

vcl-cxgridcustomtableview-dot-tcxcustomgridtableview-c2863e10.md

latest4.9 KB
Original Source

TcxCustomGridTableView.OnCustomDrawPartBackground Event

Allows you to custom draw a View element background.

Declaration

delphi
property OnCustomDrawPartBackground: TcxGridPartCustomDrawBackgroundEvent read; write;

Remarks

This event fires for the following elements:

  • Filter panel
  • Find panel
  • Footer panel
  • Group footer panel
  • Group By box

The OnCustomDrawPartBackground event’s Sender parameter identifies the View whose element is to be painted. The ACanvas parameter provides the drawing surface. The ADone parameter specifies whether default painting should be done after the event handler’s execution. Set this parameter to True if you have painted the element and default processing is not required.

The AViewInfo parameter provides access to the ViewInfo object whose properties and method allow you to get information about the painted element. For instance, you can determine the element to be painted and obtain the element’s bounds using this object’s Bounds property. The table below lists all the elements available for custom painting using the event and the corresponding ViewInfo object types (class names).

ElementViewInfo Class Name
Filter panelTcxGridFilterViewInfo
Find panelTcxGridFindPanelViewInfo
Footer panelTcxGridFooterViewInfo
Group footer panelTcxGridRowFooterViewInfo
Group By boxTcxGridGroupByBoxViewInfo

In the example below, the Group By box is custom painted by handling the OnCustomDrawPartBackground event. The box is rendered with a custom image loaded from an external file. For other View elements, the default painting is used.

delphi
var
  APatternBrush: TBrush; // A brush used to fill the "group by" box
procedure TForm1.FormCreate(Sender: TObject); // Creates a pattern brush from a texture
begin
  APatternBrush := TBrush.Create;
  APatternBrush.Bitmap := TBitmap.Create;
  APatternBrush.Bitmap.LoadFromFile('c:\texture1.bmp');
end;
procedure TForm1.cxGrid1DBTableView1CustomDrawPartBackground(Sender: TcxGridTableView; ACanvas: TcxCanvas; AViewInfo: TcxCustomGridCellViewInfo; var ADone: Boolean); // An OnCustomDrawPartBackground event handler
begin
  if AViewInfo is TcxGridGroupByBoxViewInfo then // If the drawn UI element is a "group by" box
  begin
    ACanvas.Brush := APatternBrush; // Assigns the loaded pattern brush to the canvas
    ACanvas.FillRect(AViewInfo.Bounds); // Fills the "group by" box with the pattern brush
    ADone := True; // Disables the predefined draw routine for the "group by" box
    end else
      ADone := False; // Enables the predefined draw routines for other UI elements
  end;
end;
// Releases the pattern brush when the form is destroyed
procedure TForm1.FormDestroy(Sender: TObject);
begin
  APatternBrush.Bitmap.Free;
  APatternBrush.Free;
end;
cpp
TBrush *APatternBrush; // A brush used to fill the "group by" box
void __fastcall TMyForm::FormCreate(TObject *Sender) // Creates a pattern brush from a texture
{
  APatternBrush = new TBrush();
  APatternBrush->Bitmap = new Graphics::TBitmap();
  APatternBrush->Bitmap->LoadFromFile("c:\\texture1.bmp");
}
void __fastcall TMyForm::cxGrid1DBTableView1CustomDrawPartBackground(TcxGridTableView *Sender, TcxCanvas *ACanvas, TcxCustomGridCellViewInfo *AViewInfo, bool &ADone) // An OnCustomDrawPartBackground event handler
{
  if(AViewInfo->InheritsFrom(TcxGridGroupByBoxViewInfo)) { // If the drawn UI element is a "group by" box
    ACanvas->Brush = APatternBrush; // Assigns the loaded pattern brush to the canvas
    ACanvas->FillRect(AViewInfo->Bounds); // Fills the "group by" box with the pattern brush
    ADone = true; // Disables the predefined draw routine for the "group by" box
  } else
    ADone = false; // Enables the predefined draw routines for other UI elements
}
// Releases the pattern brush when the form is destroyed
void __fastcall TForm1::FormDestroy(TObject *Sender)
{
  delete APatternBrush->Bitmap;
  delete APatternBrush;
}

The following screenshot shows the result of handling the event.

See Also

TcxCustomGridTableView.FilterBox

TcxGridTableOptionsView.Footer

TcxGridTableOptionsView.GroupByBox

TcxGridTableOptionsView.GroupFooters

TcxGridTableOptionsView.GroupRowHeight

TcxCustomGridTableView Class

TcxCustomGridTableView Members

cxGridCustomTableView Unit