Documents
NextGrid & NextDBGrid
- Integrating Inplace Editors
- Upgrade existing projects for loading changes
- FieldChooser Tutorial
- NextGrid How To
- Html Column Tutorial
- NextGrid Slide Style Tutorial
- InputLine Tutorial
- Edit events in NextGrid
- NextGrid Vista Style
NextGrid
- NextGrid Quick Start
- Graphic Column Tutorial
- Optimize NextGrid
- Custom Draw in NextGrid
- VirtualColumn Tutorial
- NextGrid Custom Sorting
- TreeColumn Tutorial
NextDBGrid
NextInspector
- NextInspector Item Types
- NextInspector Quick Start
- NextDBInspector Tutorial
- NextInspector Advanced tutorial
- Map VCL property to item
NextSheet
NextCollection
- NxInfoPanel Tutorial
- NxPathControl and NxNotebook tutorial
- NxAlertWindow Tutorial
- NxPathControl Quick Start
- NxButton Tutorial
- NxOutlookBar Tutorial
- NxFlipPanel and NxHeaderPanel Quick Start
- NxPageControl and NxNotebook Quick Start
Misc
- DateTime FormatMask
- NxAutoCompletion Tutorial
- Using NxColorScheme
- NxComboBox styles
- Enable typing unicode characters in InplaceEditors
- NxProgress Tutorial
- NxPreview Quick Start
- Numeric FormatMask
- Component Names Change
- 32bit Bitmaps Tutorial
Labs
Custom Draw in NextGrid
Related Articles:
Info
- Skill:
- Version: 1.0.1
- Author: Bojan Nikolic
- Created:
- Updated: 2008-05-13
1. Set column for custom draw
Cell is not drawn in custom mode by default. This is controled by DrawingOptions property of Column:
| Name | Meaning |
|---|---|
| doNormal | Cells within this column are drawn without custom draw. |
| doCustom | Cell will be drawn as usuall, but custom code may be added as extra painting layer over existin drawing. |
| doCustomOnly | Cell must be drawn manualy, even a background |
| doBackgroundOnly | Background is drawn as first layer (may be selected or not), but additional drawing must be done manualy. |
2. Custom Draw Event
If you like to made some custom drawing inside cell, you will need to use OnCustomDrawCell event. This event occur, when every Cell inside Grid is drawn.
This event have next parameters:
| Name | Meaning |
|---|---|
| ACol | Column Index of currently drawing cell |
| ARow | Row Index of currently drawing cell |
| CellRect | TRect of currently drawing cell |
| CellState | Cell state of currently drawing cell |
ACol and ARow parameters are useful for checking cell content of this cell before you draw.
Delphi Example:
if NextGrid1.Cells[ACol, ARow] = 'completed' then
if(NextGrid1.Cells[ACol][ARow] = "completed" {
CellRect help when drawing need to fit inside currently drawing cell.
NextGrid1.Canvas.MoveTo(CellRect.Left, CellRect.Top); NextGrid1.Canvas.LineTo(CellRect.Right, CellRect.Bottom);
NextGrid1->Canvas->MoveTo(CellRect->Left, CellRect->Top); NextGrid1->Canvas->LineTo(CellRect->Right, CellRect->Bottom);
This example draw cross line inside current cell.
CellState parameter identify state (if cell selected or not) of currently painted cell.
This parameter is useful for different drawing for selected and non-selected cells.
Full example:
procedure TForm1.NextGrid1CustomDrawCell(Sender: TObject; ACol,
ARow: Integer; CellRect: TRect; CellState: TCellState);
var
R: TRect;
begin
R := CellRect;
InflateRect(R, -2, -2);
with NextGrid1.Canvas do
begin
if csSelected in CellState then
Pen.Color := clHighlightText
else
Pen.Color := clGray;
Brush.Color := clRed;
Rectangle(R);
end;
end;
Result:

3. Background Custom Draw
Background may be custom drawn too, very similar as drawing custom cells.
This need to be done within OnCustomDrawCellBackground event.
When DefaultDrawing parameter is set to False standard drawing will be skipped, and custom drawing will be applied.
| Name | Meaning |
|---|---|
| ACol | Column Index of currently drawing cell |
| ARow | Row Index of currently drawing cell |
| CellRect | TRect of currently drawing cell |
| CellState | Cell state of currently drawing cell |
| DefaultDrawing | When set to False, custom drawing will be used. |
Example of drawing "3D" effect cells:
procedure TForm1.NextGrid1DrawCellBackground(Sender: TObject; ACol,
ARow: Integer; CellRect: TRect; CellState: TCellState;
var DefaultDrawing: Boolean);
var
R: TRect;
begin
if not(csSelected in CellState) then
begin
DefaultDrawing := False;
with NextGrid1.Canvas do
begin
R := CellRect;
Frame3D(NextGrid1.Canvas, R, clBtnHighlight, clBtnShadow, 1);
Brush.Color := clBtnFace;
FillRect(R);
end;
end;
end;
Result: