Delphi and Lazarus
Trekking and Events
Blog and Forum
Čeština English
Main menu
Delphi and Lazarus
Top downloads


There were several reasons for me to write an own grid component for Delphi:

- Borland's inoperability to fix reported bugs (this applied not only for TStringGrid)

- I wanted different editing controls like TEdit, TComboBox, TCheckBox to be inserted in cells

- I wanted the last column to be aligned within the client area edge

- I wanted a slightly better behavior while moving or resizing columns or rows

Now KGrid has a lot of features and is becoming a versatile solution for table visualisations, table data modifications and creating table reports under Delphi and Lazarus IDEs. Everything is provided royalty free and with complete source code (however, it is copyrighted software, more information about the license can be found in the header of each source file).

KGrid features
Written as TCustomControl descendant, this is not a TCustomGrid enhancement
95% compatible with TDraw(String)Grid
Any TWinControl descendant can be used as inplace editor.
Cell clipping and double buffering
Cell merging and splitting. Robust and versatile solution.
Column/row/grid autosizing
Contains the database control TKDBGrid
Cross platform solution in Lazarus
Each color can be modified at design time
Editable/selectable fixed cells
Index mapping - a technique that greatly simplifies event handling when columns and/or rows change their positions
Last column or row can be aligned - corresponding scroll bar will not appear
OS themes fully supported including Windows Vista/7 themes
Printing and previewing. Robust solution. On the fly previewing - changes to the grid are instantly previewed. Printing a table in Delphi has never been easier.
Row and column hiding with optional visual indication
Rows, columns and cells (optional) are implemented as classes
Several styles for moving and resizing of rows or columns
Single source and the same functionality in both Delphi and Lazarus
Unicode component. For ANSI Delphi versions (up to 2007) no unicode inplace editors are available - you must take these somewhere else (e.g. from TMS Unicode controls).
Various text output attributes (works on all platforms)- multiline text, end ellipsis, path ellipsis, word break
Versatile cell painting interface (drawing cells with various attributes, thumbnail/image cells, checkbox cells,...)
Versatile design of cell events
Versatile sorting interface
Virtual grid possibility - data will not be stored in the grid directly but somewhere else in the application

Necessary packages

From version 1.3 none. Up to version 1.3 beta JEDI Code Library (JCL) - Version 1.100+ - download here.

Compiled executable demo

Download the demo executables (Delphi only) directly without compiling in Delphi:

KGrid downloads

Note: there are only stable packages here. For latest changes and hotfixes please download KControls.

FileVersionNumber of
Available tools:Changes
N/Ahigher than 1.7N/AN/ANewer versions available only in KControls package
kgrid_1.7.zip1.76779Delphi 6+, Lazarus 0.9.29(SVN#21827)+, C++Builder 2007+update for RAD Studio XE, editable fixed cells, Vista style selection
9.12.2010 important patch
kgrid_1.6.zip1.61255Delphi 6+, Lazarus 0.9.29(SVN#21827)+, C++Builder 2007+column/row/grid autosizing and many other improvements and bugfixes
kgrid_1.5.zip1.51707Delphi 6+,Lazarus 0.9.29(SVN#21827)+tiny modifications due to releasing KControls
kgrid_1.5beta.zip1.5 beta228Delphi 6+,Lazarus 0.9.29(SVN#21827)+printing and previewing (Lazarus only Win32), drawing thumbnail/image cell
kgrid_1.4.zip1.4725Delphi 6+,Lazarus 0.9.29(SVN#21827)+full Lazarus support (all widget sets), database control TKDBGrid, cell merging/splitting, smooth scrolling and much more. 3.10.2009 hotfix: painting performace increased (QT, GTK2). 4.10.2009 hotfix: PgUp/PgDn key fix, new minor options in TKDBGrid
KGrid_1.3.zip1.3695Delphi 6+,Lazarus 0.9.26+doesn't need JCL, port to Lazarus(Win32), ThroughClick property, text output attributes.
KGrid_1.3beta.zip1.3 beta194Delphi 6+Column/row visibility, more sorting styles & other fixes.
KGrid_1.2.zip1.22528Delphi 6+Update for Delphi 2009, minor fixes, OnChanged event, documentation update
22.10. hotfix for Delphi6-7
KGrid11.zip1.11500Delphi 6 till 2007Sorting interface, cell clipping and double buffering, TKGridCellPainter class, another improvements and fixes, documentation update
KGrid10.zip1.01086Delphi 6 till 2007Index mapping, demo, finished documentation, many bugfixes and improvements
KGrid09.zip0.9345Delphi 6 till 2007Initial release

Screenshots (click the images to enlarge)

Simple KGrid demonstration programArbitrary TWinControl descendant can be used as inplace editor
Cell merging, TKGridAttrTextCell demoPrint preview
Disabled gridDocumentation preview
Main demo in Lazarus/Linux (GTK2)Advanced header demo in Lazarus/Linux (GTK2)
Simple database demo in Delphi/Windows XP

Home | Software | Delphi and Lazarus | Trekking, travelling | Sport | Others | Blog

Search in comments: 
inserted: 2015-07-18 17:50:54   Reply...
From: KCa17d
Hi, very usefull and powerfull Grid, personaly a choose it to work with ;-) Like i'am newbe in delphi, i use the grid in the most simple way, as grid text display modify and save, KGrid.Cells[Col,Row] := Text So now a would like to use color in a individual Cell like : if KGrid.Cells[Col,Row] = 'TEXT' then begin KGrid.Cell[Col,Row].Font.Color := clWhite; KGrid.Cell[Col,Row].Brush.Color := clRed; end; Is there a similar way to do it in this simple way ?????
inserted: 2015-05-01 21:49:34   Reply...
From: robsosno
I have similar issue as Calinutz. I'm filling KGrid with data and in some cases when there is none I would like to see only header. However it is not possible. You can also observe in designer that when FixedRows=1 and you decrease RowCount to 1 then FixedRows changes to 0. Exactly the same behaviour I see in standard TStringGrid which is strange because implementation is quite different.
inserted: 2015-04-28 08:59:51   Reply...
From: bdkacz
Hello. How can I force execute EditorDataToGrid from outside the grid - for example I have "save" button to save data from grid to database,but some users after enter data to last cell doesn't click to another cell to fire the EditorDataToGrid event = the cell is empty when I access it in save loop. So I must programically save entered text to grid (and then to database) - but how ?
inserted: 2015-04-07 15:21:46   Reply...
From: Peshte
Hi. I have some issues related to multiline cell and KGrid1DrawCell event. Plase join the topic from,27858.0.html Thank you.
inserted: 2015-03-15 14:58:58   Reply...
From: ax78
KGrid produces wrong output with the following code: TMyCell(KGrid1.Cell[1,1]).Text:='Hallo '+sLineBreak+'Text'; TMyCell(KGrid1.Cell[1,1]).Attributes := [taLineBreak]; TMyCell overwrites ApplyDrawProperties and assignes the needed Attributes ("Grid.CellPainter.Attributes := Attributes;") Changing the Line 2474 in KGraphics.pas (adding "+1") solves the problem. ....> tbfDraw: Draw(Vert, TrimStart, TrimLen); ....> end; 2474> LineBegin := Index+1; ....> end; ....> Inc(Vert, FFontHeight * LineBreaks);
inserted: 2015-01-02 21:51:26   Reply...
From: Marcio
When I make a row or column invisible it turns to a green line. Can I make it totally invisible or change this feature color?
inserted: 2015-01-02 21:34:23   Reply...
From: Marcio
Hello. How can I change a ComboBox cell value not manually after the cells were created, by reading a file for example? And then, how to pick the index value of a cell?
inserted: 2014-09-17 20:06:11   Reply...
From: DwnTwn
Any examples (please point to link) using KDBGrid and cell-wordwrap? Any comprehensive (English) documentation?
inserted: 2014-07-06 11:09:27   Reply...
From: tk
Please write your comments on KControls page. Thank you.
inserted: 2014-05-31 16:11:35   Reply...
From: Tom
Hello How to change the color of a green triangle in the sorting (goRowSorting) ?
inserted: 2014-07-27 13:33:45   Reply...
From: tk
Green triangle is the image stored in TKGridCellPainter. It is loaded from kgrids.res. Easy way to modify that image could be create your own descendant of TKGridCellPainter and populate FSortArrow with new bitmap image. That bitmap should be 32 bpp with alpha channel.
inserted: 2014-01-27 16:47:41   Reply...
From: ribarvlada
Hello, How I can change text in column header and make heder to loocks like on images at site.
inserted: 2014-01-27 12:23:48   Reply...
From: krzynio
Is there a filter option in dbgrid? If not, do you plan to implement it?
inserted: 2014-07-27 13:38:11   Reply...
From: tk
We will need tree columns and possibly filters in our new software as well so there is big chance these features will be implemented.
inserted: 2014-01-22 16:04:31   Reply...
From: anubis
Hi!, Is it possible to scale a grid to print?. When i use a grid with 2 columns, it prints in all wide. thanks
inserted: 2014-01-21 21:55:07   Reply...
From: Cogitosum
Moving rows in KGrid hangs on an application on Delphi2006 in versions 1.6 and 1.7. In version 1.5 is ok. Why?
inserted: 2014-07-27 13:36:10   Reply...
From: tk
Should be fixed in KControls v1.5 and higher.
inserted: 2013-11-22 13:12:46   Reply...
From: MiroM
Sorting Rows is Case sensitive. Can I make it to be Case insensitive? Example: Xray is before ant.
inserted: 2013-03-14 18:39:43   Reply...
From: Calinutz
I found a bug in TKDBGrid. When connecting the datasource of the grid to an empty dataset (active), the fixed row (with column headers) dissappears. And even after the dataset gets populated, the fixed row remains inexistant, and you cannot change the fixedRows property manually to force it to show the column headers. I think this is a bug
inserted: 2014-07-27 19:22:20   Reply...
From: tk
This has been fixed in v1.6.
inserted: 2013-03-10 23:44:06   Reply...
From: Calinutz
Please explain to me how to use the titles of the columns in KDBGrid? I mean I would like to be able to pick which columns from a query I want displayed (without having to change the query for it each time. Also I would like to be able to set the title for the column without having to change the query for it. Is it possible? A query like this: select field1,field2,field3 from table1 I should be able to set somehow the title for the 3 columns in the DBGrid without having to alter the query to look like this: select field1 as "Title for column 1", field2 as "Title for column 2", field3 as "Title for column 3" from table - Also, how can I make one column ReadOnly, (exmpl. column 2)? This question goes for both Grids, KGrid and kDBGrid
inserted: 2013-03-13 07:05:42   Reply...
From: Calinutz
Since everybody seems busy... I will answer my own question (partially). In order to get the readonly effect on certain columns (or rows apparently) you need to access the onEditorCreate Event, and place there some conditions when to show the editor and when to not. Like this: procedure TMain.KGEdCreate(Sender: TObject; ACol, ARow: Integer; var AEditor: TWinControl); var InitialCol, InitialRow: Integer; begin InitialCol := KGrid1.InitialCol(ACol); // map column indexes InitialRow := KGrid1.InitialRow(ARow); // map row indexes if InitialRow = KGrid1.FixedRows then Exit; if InitialCol = 3 then AEditor := TEdit.Create(nil); end; Using the above code, only on column 3 you will have an editbox shown. The rest of the columns will seem readonly... you cannot edit them. Sure, you might have other editors on other columns (checkboxes, comboboxes and so on) so be sure to add them to the conditions in the code above.
inserted: 2013-03-13 07:11:39   Reply...
From: Calinutz
The event procedure name should be TMain.KGrid1EditorCreate... I renamed my kgrid and obviously that changed the events name. So do not get distracted by that. This kGrid looks amazing and seems to be able to do stuff that I looked for, for a long time in a grid. Embarcadero should contact you and IMHO they should include your controls by default in their IDE. If I will discover other "hidden" functionality for this grid, I will post it here.
inserted: 2013-02-13 12:33:24   Reply...
From: Ulrich
Hello, how can I define read only columns/cells? With best regards- Ulrich
inserted: 2012-11-29 09:23:33   Reply...
From: kafino
Ahoj narazil jsem na problém s KGridem. Když vložim na jeden formulář dva KGridy a mám ještě jeden třeba i prázdný formulář a překlikávám mezi formuláři stane se to že: Když označím první KGrid a pak druhý formulář a zpět, tak to je v pořádku, ale když označím první KGrid, pak formulář a pak druhý KGrid, aplikace zatuhne. Stane se to že si začnou oba KGridy krást fokus a aplikace se zacyklí. Mám Delphi 2007 a KGrid v1.7.
inserted: 2014-03-14 08:36:07   Reply...
From: mirda
Ahoj. Řešil jsem stejný problém. Stačí zakomentovat v KGrids.pas/TKCustomGrid.LateUpdate volání SafeSetFocus. Není to oprava ale odstraní to problém. Nicméně bylo by dobré to někdy dořešit.
inserted: 2012-08-09 06:07:22   Reply...
From: HIGH-Zen
Hi tk! I am using KGrid more than a year. It's great Component. I've noticed that the input is not working properly. Win XP, Lazarus 0.9.30, FPC 2.4.2; W7, Lazarus 1.1, FPC 2.7.1. KGrid 1.7, goEditing=True, goAlwaysShowEditor=False. If keyboard input language is set up Latvian (e.g. Latvian (QWERTY)), i can't input first special character properly. E.g. Alt+a must be ā, got empty, Alt+k must be ķ, got 7, Alt+ i must be ī, got +. Following characters work as expected. E.g. Alt+k and Alt+k, got 7ķ. For example TStringGrid with goEditing=True input works normally - Alt+k and Alt+k, got ķķ.
inserted: 2012-07-19 14:56:43   Reply...
From: Duhacek
Corrected my function SumCol... function SumCol(AGrid: TKCustomGrid; ACol: integer): Extended; var iRow, eCode: integer; dbl: Extended; begin Result:= 0; for iRow:=0 to AGrid.RowCount-1 do begin Val(AGrid.Cells[ACol-1,iRow], dbl, eCode); if (eCode=0) then Result:= Result + dbl; end; end;
inserted: 2012-07-19 14:20:25   Reply...
From: Duhacek
Can you add this function to TKGrid? I needed it in my program so I'd like to share this code... function SumCol(AGrid: TKCustomGrid; ACol: integer): Extended; var iRow: integer; begin Result:= 0; for iRow:=0 to AGrid.RowCount-1 do try Result:= Result + StrToFloat(AGrid.Cells[ACol-1,iRow]); except end; end;
inserted: 2012-06-22 02:56:41   Reply...
From: nomas
I suggest some code for More reliable start to editing at goAlwaysShowEditor = False, It send IME message to Editor. And TKIcon has error at 'TKIcon.AddFromPng' with BDS 2006, there is misplace USE_PNG_SUPPORT, I guess. {$IFDEF MSWINDOWS} procedure TKCustomGrid.WMIMEStartComposition(var Msg: TMessage); begin if not EditorMode then begin EditorMode := True; if EditorMode then FEditor.Perform(Msg.Msg,Msg.WParam,Msg.LParam); end; end; procedure TKCustomGrid.WMIMEComposition(var Msg: TMessage); begin if EditorMode then FEditor.Perform(Msg.Msg,Msg.WParam,Msg.LParam); end; {$ENDIF}
inserted: 2012-04-10 21:30:23   Reply...
From: mtbf40
Hello, how can I write bold text in single cells? example: c1-Info1(bold) c2-Info1_1 c3-Info1_2 c4-Info1_3 c5-Info2 (bold) c6-Info2_1 c7-Info2_2 c8-Info2_3
inserted: 2012-04-08 17:34:49   Reply...
From: Donato
Does anyone have a simple example of how to use the TCheckBox TKgrid? Alguém teria um exemplo simples de como utilizar Tcheckbox no TKgrid?
inserted: 2012-04-04 10:46:53   Reply...
From: kucing
When using TComboBox as in place editor, the drop down list does not show up. One of the workaround is by using "xpman.res", but this cause display issue on Windows 7. Please if you can fix this on the next version. Thank you.
inserted: 2012-03-29 13:48:47   Reply...
From: MilorD
Good day! I wanted to know whether a component KGrid for Embarcadero RAD Studio XE 2. I would very much like to. Thank you.
inserted: 2012-03-30 09:22:42   Reply...
From: tk
Yes I will upgrade the component pack to XE 2 soon.
inserted: 2012-01-21 13:08:51   Reply...
From: carre
Hi, i try to change the color of a cell (based on demo) - with TKGridAttrTextCell(Analyse_KGrid1.Cell[cellrow,cellcol]) do begin Text := 'No Problem'; Brush.Style := bsSolid; Brush.Color := RGB(128 + Random(127), 128 + Random(127), 128 + Random(127)); end; Text statement is without a problem but on the Brush statement Lazarus rise a external exception SIGSEGV - any idea?
inserted: 2012-01-22 11:01:45   Reply...
From: carre
I found my fault (register custom cell class was missing).
inserted: 2012-01-19 13:34:27   Reply...
From: gwiethaus
Bug Detected: Delphi 2007 Windows 7 Professional 64 bit. The object instance is not set FCells. It happens when I use the method Objects []. TKCustomGrid.SetObjects shoots, but FCells is not set. So my objects can not be linked with the cell. The code is below. //in showform event KGrid1.Objects[1,1]:= Combobox1; //in KGrids.pas (KControls Package) procedure TKCustomGrid.SetObjects(ACol, ARow: Integer; Value: TObject); var Cell, Tmp: TKGridCell; begin //Bug Here in FCell do not is set, FCells = nil if Assigned(FCells) and ColValid(ACol) and RowValid(ARow) then begin FlagSet(cGF_GridUpdates); ... ... end; Sincerely, Guilherme Wiethaus, São Paulo / Brazil
inserted: 2012-01-04 14:26:38   Reply...
From: PicoDeP
Thank you for sharing your component! I only modified the following code because I think that VisibleColCount and VisibleRowCount don't work propertly: function TKCustomGrid.GetVisibleColCount: Integer; begin Result := LastVisibleCol - FTopLeft.Col + 1; end; function TKCustomGrid.GetVisibleGridRect: TKGridRect; begin Result := GridRect(FTopLeft.Col, FTopLeft.Row, LastVisibleCol, LastVisibleRow); end; function TKCustomGrid.GetVisibleRowCount: Integer; begin Result := LastVisibleRow - FTopLeft.Row + 1; end;
Older comments
My account
Recently modified

KControls Development Suite

by: tk



by: tk



by: tk



by: tk


KGrid 1.3 released.

by: tk


Recently inserted

My recent work on KMemo

by: tk


Update for RAD Studio XE2

by: tk


Slow progress

by: tk


Problem with comments and logins

by: tk


KControls released

by: tk


Working hard on KGrid update...

by: tk