Documents
NextGrid & NextDBGrid
- Html Column Tutorial
- Upgrade existing projects for loading changes
- Edit events in NextGrid
- NextGrid Vista Style
- NextGrid How To
- Integrating Inplace Editors
- NextGrid Slide Style Tutorial
- InputLine Tutorial
- FieldChooser Tutorial
- Using Editors in runtime
- Grid Report Tutorial
NextGrid
- TreeColumn Tutorial
- NextGrid Quick Start
- Custom Draw in NextGrid
- Export to XML from NextGrid
- Optimize NextGrid
- NextGrid Custom Sorting
- VirtualColumn Tutorial
- Graphic Column Tutorial
NextDBGrid
- NextDBGrid Quick Start
- NextDBGrid Events
- NextDBGrid How To
- Sorting records in NextDBGrid
- LookupColumn Tutorial
NextInspector
- NextInspector Advanced tutorial
- ToolbarItem tutorial
- NextDBInspector Tutorial
- NextInspector Item Types
- Map VCL property to item
- NextInspector Quick Start
NextSheet
NextCollection
- NxAlertWindow Tutorial
- NxInfoPanel Tutorial
- Vista Styled Panels
- NxPathControl and NxNotebook tutorial
- NxPathControl Quick Start
- NxFlipPanel and NxHeaderPanel Quick Start
- NxOutlookBar Tutorial
- NxPageControl and NxNotebook Quick Start
- NxButton Tutorial
Misc
- Component Names Change
- NxComboBox styles
- Numeric FormatMask
- NxVirtualDataSet tutorial
- DateTime FormatMask
- NxPreview Quick Start
- 32bit Bitmaps Tutorial
- Quick update
- Enable typing unicode characters in InplaceEditors
- Using NxColorScheme
- NxProgress Tutorial
- NxAutoCompletion Tutorial
Labs
NextGrid .NET
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: