Software
Delphi and Lazarus
Trekking and Events
Blog and Forum
Čeština English
Main menu
Delphi and Lazarus
Useful Links

interesting webs & galleries of my friends:

F-Web

Máša&Pája Gallery

Delphi and Lazarus:

Embarcadero/ CodeGear

Lazarus project

Torry's Delphi pages

JEDI Code Library

 

KGrid

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: KGridDemos.zip

KGrid downloads

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

FileVersionNumber of
downloads
Available tools:Changes
kgrid_1.7.zip1.72853Delphi 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.61106Delphi 6+, Lazarus 0.9.29(SVN#21827)+, C++Builder 2007+column/row/grid autosizing and many other improvements and bugfixes
kgrid_1.5.zip1.51627Delphi 6+,Lazarus 0.9.29(SVN#21827)+tiny modifications due to releasing KControls
kgrid_1.5beta.zip1.5 beta168Delphi 6+,Lazarus 0.9.29(SVN#21827)+printing and previewing (Lazarus only Win32), drawing thumbnail/image cell
kgrid_1.4.zip1.4610Delphi 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.3600Delphi 6+,Lazarus 0.9.26+doesn't need JCL, port to Lazarus(Win32), ThroughClick property, text output attributes.
KGrid_1.3beta.zip1.3 beta147Delphi 6+Column/row visibility, more sorting styles & other fixes.
KGrid_1.2.zip1.22454Delphi 6+Update for Delphi 2009, minor fixes, OnChanged event, documentation update
22.10. hotfix for Delphi6-7
KGrid11.zip1.11425Delphi 6 till 2007Sorting interface, cell clipping and double buffering, TKGridCellPainter class, another improvements and fixes, documentation update
KGrid10.zip1.01014Delphi 6 till 2007Index mapping, demo, finished documentation, many bugfixes and improvements
KGrid09.zip0.9266Delphi 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: 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;
inserted: 2011-11-28 11:42:02   Reply...
From: jani
Seems good component, but i really cant install it or compile demos. I have Delphi 5 and the error i get is "line to loong" for kcontrols.inc. How can i fix it ?
inserted: 2011-10-25 09:29:44   Reply...
From: christensen
Hi, amazing component, thanks! Now my problem:i want to display checkbox in the kgrid, the bd is Fifebird 2.1.3(smallint type field stores the boolean values:0 and 1) How can i display the content of this type of fields in kgrid, but with checkboxes? Thanks
inserted: 2011-10-05 18:00:25   Reply...
From: kalagan
If I set property ScrollBars to ssVertical (or ssHorizontal) at design time, scrollbars are not displayed as expected (both are not visible). How can I do to always show scrollbars?
inserted: 2011-10-05 17:56:04   Reply...
From: kalagan
How can I have a grid with 0 rows? If I set rowcount:=0 it doesn't work.
inserted: 2011-09-12 22:45:09   Reply...
From: Anzo
I have a problem with TKdbGrid. I have dataset with several fields, and TKdbGrid draw column for each field. But I`m want draw only one of them. Please show me little snippet of TKdbGrid header/column config.
inserted: 2011-09-10 13:11:46   Reply...
From: Robert
How can i print the KGrid without fix number column. can printview like dbgrideh
inserted: 2011-09-09 10:02:06   Reply...
From: xcod
In TDBGrid by pressing the cursor down a new row added. In TKDBGrid not added. Why?
inserted: 2011-09-01 00:05:26   Reply...
From: Rass87
Hello everyone, I just installed the KGrid package on Lazarus (v 0.9.30) and I have a little problem (?): I can't edit the fields of my grid at all. I mean I assumed that the columns of these grid components can be edited the same way as the common DBGrid's: double-click it in the designer and the column editor opens. Instead of this, I only get an OnClick event handler procedure created as a result. Could someone tell me what am I doing wrong here please? :)
inserted: 2011-08-25 00:17:13   Reply...
From: vovach777
OnSelectionExpand property do not work on 1.7 release of KGrid
inserted: 2011-07-21 07:07:52   Reply...
From: DsLin
KGrid is a very nice control. Thanks a lot for your contribution. Now, I want to output some multiline text in a cell, and I found that there is no LineSpace attribute in CellPainter, so I suggest to add this attribute to CellPainter, it will greatly make long length text more beautiful. It's code may like this in below: (procedure Initialize is subprocedure of procedure DrawAlignedText() in KGraphics.pas) procedure Initialize; begin ClipRect := ARect; InflateRect(ClipRect, -HPadding, -VPadding); DC := Canvas.Handle; FontHeight := GetFontHeight(DC) + LineSpace; //Here is the key point end;
inserted: 2011-06-25 14:03:30   Reply...
From: hairdresser
Dobrý den.... Potřebuji obarvit buňku po stisku tlačítka... Zkoušel jsem téměř vše
inserted: 2011-06-08 21:38:27   Reply...
From: Stuart
I'm not a great programmer so please bear with me. I'm trying to make a tiny sudoku application and only need for it to display nicely. The KGrid is much better than the default grids and I'm sure it is perfect but I need to get more out of it. How can I change the font color in individual cells without changing the font color in all other cells?
inserted: 2011-11-05 08:50:16   Reply...
From: Suren Sarathkumara
In OnDrawCell event if (ACol = x) and (ARow = y) then KGrid1.CellPainter.Canvas.Font.Color := $ABABAB;
inserted: 2011-05-18 13:55:00   Reply...
From: Matt
Hi! I've been using your KGrid component for a while and I like it very much. But now it seems I have found a bug. I use Delphi XE. I put only KGrid on the Form and enable sortable columns. Now when I compile the application, column sorting works fine if I run application on Windows 7, but when I run it under Windows XP the whole application freezes (and has to be shut down with Task Manager). Can you tell me how to fix this so my application will work under Windows XP? Best regards, Matt
inserted: 2011-05-19 09:07:30   Reply...
From: Matt
I made a mistake. The problem is not with column sorting, but with column moving. Application freezes when I try to move column (when using KGrid, compiling on Delphi XE and running under Windows XP).
inserted: 2011-05-31 11:19:01   Reply...
From: Matt
Has anybody been able to find a fix for this? Any workarounds?
inserted: 2011-12-04 10:14:15   Reply...
From: Tulkas
I have the same problem with Delphi7 and Windows XP. Solved changing property DragStyle to dsLine or dsXORLine.
inserted: 2011-09-09 15:16:33   Reply...
From: truetom
I have same problem.
inserted: 2011-05-15 12:41:57   Reply...
From: batozai
halo i have tried it for hours, but i didn't figure it out. i used to use TAdvstringgrid from TMS component in delphi. now i use TKGrid. i need to know how to acces inplaceditor event on kgrid component. i have add a tbutton to a grid column, now i want to acces the onclick event of the button. i also add an edit component as inplace editor, now i want to acces the onchange event of the edit component..... how do i do that ? may later i will add another tcontrol component as inplace editor...... thanks in advance
inserted: 2011-05-15 22:22:21   Reply...
From: tk
In KGrid you have to write the handler yourself and assign it to the inplace editor in code.
inserted: 2011-05-16 02:51:36   Reply...
From: batozai
hi tk can you please give me example how to make the handler...? i have made a procedure that i want to call when the button is clicked. also when the combobox is click.... from what event of kgrid i should handle this ? thanks in advance
inserted: 2011-04-14 19:55:56   Reply...
From: Philips10
Using KControls Development Suite under Lazarus: Will the application I use it to program with be cross-platform (Mac Linux, OpenBSD/UNIX, Windows) compatible? Since the package (as I need KGrid in partic.) uses the Jedi package I begun to have some doubts, though you wrote on your site "Cross platform solution in Lazarus". Another question: I guess I can use the ZeosLib with eg PostgrSQL or SQLite? That must be the case too! Had no tine to try it out... Thank you very much in advance.
inserted: 2011-04-15 12:21:06   Reply...
From: Philips10
..those were not so clever questions to ask for real... But I have a request: Could you please program a footer to your 1st class K(DB)Grid for financial applications? Please work on this, will you? I really need that bonus! A big thanks in advance!
inserted: 2011-04-16 21:24:00   Reply...
From: tk
Hi I am out of time these months. Volunteers are welcome to put KComponents to some other place managed by SVN/CVS. This means NOT that I won't be able to continue this development but for this year you cannot expect much progress. Because of that it is better for these components to become open source.
inserted: 2011-04-22 21:23:07   Reply...
From: sourceforge.net
Some other place as an open source-project with SVN (better than CVS) - repr.? www.sourceforge.net would be the best place to put it. Right now, I have started with my acounting studies, so I won't be having much time to "guard over" your KGrid. Becides..it would be not to "cool" of me to take over your work. Fa more developers would be working with and for KGrid. You could eg give some ideas to those (like that footer,...) Great idea!
inserted: 2011-04-13 19:22:53   Reply...
From: martinrame
Hi TK. Do you plan to add SVN/Git access to the development tree?. I'm sure there are some people interested in sending fixes/improvements to the component.
inserted: 2011-04-16 21:18:14   Reply...
From: tk
I am sorry but I am out of time these months. Anybody is welcome to give KComponents to a SVN managed location.
inserted: 2011-03-31 03:01:52   Reply...
From: Daniel
HI! Thanks for so faboulus component! I have 2 qustions. It is possible to make a transparent grid? it is possible to draw my own Scrollbar? THanks a lot! Daniel
inserted: 2011-04-16 21:16:57   Reply...
From: tk
You need to adapt cell painting chain or scrollable window behavior.
inserted: 2011-03-05 15:38:50   Reply...
From: zhlmxh
Does KGrid support Footer? If not, are there plans to add this?
inserted: 2011-03-05 19:00:00   Reply...
From: tk
No, at least from my part.
inserted: 2011-02-25 05:04:18   Reply...
From: Avishai
Does KGrid support BiDiMode? If not, are there plans to add this?
inserted: 2011-02-25 08:54:28   Reply...
From: tk
Yes but when I have time there are other priorities that I'd like to add (tree columns, extended sorting etc.)
inserted: 2011-02-17 09:18:41   Reply...
From: Automatic refresh
Hey tk. Here's another question, that I didn't find solution. I override OnDrawCell event of TKGrid and inside I have a code like this: var Col_ : TColor; HA : TKHAlign; VA : TKVAlign; HP, VP, ND : Integer; begin if ARow = 0 then begin HA:=halCenter; VA:=valCenter; HP:=0; VP:=0; Col_:=clYellow; end ... if ACol = 0 then KC.CellPainter.Canvas.Font.Color:=clBlack else KC.CellPainter.Canvas.Font.Color:=clWhite; ... KC.CellPainter.DefaultDraw; DrawAlignedText(KC.CellPainter.Canvas, R, HA, VA, HP, VP, KC.Cells[ACol, ARow], Col_, []); However changing the color does not occur until either mouse is moved over a cell or grid is scrolled. I thought after painting it should change color. I know you've been busy lately but I need this, so that's why I bother you. Can you please help me? Regards, Javor
inserted: 2011-02-17 13:47:55   Reply...
From: tk
Oh thats terrible to read I should allow a code formatting to these comments.. But back to the issue> Your approach is incorrect. Either you use DefaultDraw or you use another painting routines. Please don't combine these. I don't see entire code but please comment out the DrawAlignedText and assign KC.Cells[x,y] to KC.CellPainter.Text before you call DefaultDraw. Then the color must be changed each time the cell is painted.
inserted: 2011-02-16 00:04:20   Reply...
From: Raymond
Is there a way to have multi-column sorting? I would like to sort by multiple columns... Sort on [Customer Status] and then [Customer Name]. Can this be done?
inserted: 2011-02-16 18:22:16   Reply...
From: tk
I'm sorry but multi-level sorting is not supported.
inserted: 2011-02-15 09:30:19   Reply...
From: Javor
Hey tk. Glad to see you're keeping up the good work! Now to the problem: long ago (in earlier versions of the KGrid control) I've posted a problem where if you make a KGrid descendant at design time and set FixedCols to 0 at design time and reopen the form an exception was raised: "Error creating form: Error reading KGrid1.ColWidths: Invalid property value". This was fixed, but the problem persists on TKDBGrid control. I'm using Delphi 2010 and checked this over 100 times - every form that I have a TKDBGrid throws an exception after reopening it with FixedCols set to 0. Any fast solution? Lol, can't compile my project and don't want to edit your code in order to have future compatibility with new versions. Thanks in advance. Regards, Javor
inserted: 2011-02-16 18:21:02   Reply...
From: tk
I'm sorry I don't have time to test that. If you find a bug pls. send to tk@tkweb.eu
inserted: 2011-02-01 14:20:20   Reply...
From: Finn
Got other questuion. Is there any command which can assaign currently edited row to DB in KDbGrids? Now i notice that i have to click elsewhere, other row if i want to post currently edited row. But what happen if i have only one row, and no other row to click? How i can post it from code? You said you aint devellopping KDBgrid but mayby you know if it spossible to post somehow. Sorry for bothering
inserted: 2011-02-01 18:34:40   Reply...
From: tk
Did you try KDBgrid.Commit from code? Anyway I have almost no time to develop even KGrid:-( And this status I expect for another 5 months...
inserted: 2011-02-02 09:47:53   Reply...
From: Finn
i work it around somhow with few lines and KDBGrid.BeforeCellUpdate(0,0); in form destroy event.
inserted: 2011-01-28 13:28:51   Reply...
From: Finn
Is there any option to disable this green colour to show when i hide some columns (In KDBGrid)? I can't find it anywhere
inserted: 2011-01-28 13:38:09   Reply...
From: Finn
Ok got it. Sorry. Gr8 tool, amzing - thank you for making it accessible for other ppl.
inserted: 2011-01-28 15:00:38   Reply...
From: Finn
At KGrid at line 5443 State := DFCS_BUTTON3STATE; shouldyn't be ?? State := DFCS_BUTTONCHECK; Because when i use it with KDBGrid field which have True value are shown as they where greyd.
inserted: 2011-01-28 21:36:15   Reply...
From: tk
This is maybe an error in tkdbgrid. Checkboxes are 3-state in kgrid. I apologize but I don´t develop db apps in Delphi anymore. Pls try to find the bug in kdbgrids code.
inserted: 2011-01-27 04:04:05   Reply...
From: Raymond
When using the virtual grid (even in the demo) when you edit a cell and then hit the arrow to move to another cell, the grid accepts the data from the edit and writes to the grid cell just fine... BUT... it also appears to take the value of the new cell (that I am moving to) and then _write_ that value to the grid as well... There are two writes issued by one edit. I have verified this in your demo program and would be happy to send you sample app. I basically set a global var and incremented it in the EditorDataToGrid event and it fired twice... once for the cell that I did edit, but again for the cell that I am moving on to. I do not want to edit that cell... I am simply moving onto that cell. Do you have a way that I can fix this behavior? Many thanks, Raymond
inserted: 2011-01-27 09:40:53   Reply...
From: tk
Well I don't experience this in any of my programs including the demo. When I set the breakpoint to my OnEditorDataToGrid event it is fired only once. This is no the case for OnEditorDataFromGrid when you hit ESC. In that case this event is fired for the cell being curretly edited for second time to cancel user changes. I tested this now shortly in Delphi XE.
inserted: 2011-01-27 20:47:25   Reply...
From: Raymond
This is quite odd... did you hit Enter or as I indicated one of the Arrow buttons??? When I press Enter, indeed, the OnEditorDataToGrid fires only once... but when I type in 'foo' and then press the [Down Arrow] the OnEditorDataToGrid fires twice. I just tried this again and put a break point in the routine and it stopped twice... Can you please verify the behavior you are having when you edit a cell and then immediately press on the [Down Arrow]. Thanks, Raymond
inserted: 2011-01-27 20:53:55   Reply...
From: Raymond
I found out some more info!!!!!!!!!!! Try this.... go into the grid properties, Options, and set goAlwaysShowEditor to False. Run the demo (virtual grid example) edit a cell and immediately press the Down arrow and see how many times the OnEditorDataToGrid fires... it fires twice... but if I set the goAlwaysShowEditor to True then it only fires once. Thanks again for the help!! -Raymond
inserted: 2011-01-28 01:21:06   Reply...
From: Raymond
tk, I think I found the problem... on line 12541, there was no check to see if we really need to destroy and create another control by checking the KGrid.Options property for goAlwaysShowEditor. I made the following change: {old} PosChanged := (FEditorCell.Col <> Col) or (FEditorCell.Row <> Row); {new} PosChanged := ((FEditorCell.Col <> Col) or (FEditorCell.Row <> Row)) and (goAlwaysShowEditor in Self.Options); With this change, the editor is not created a second time in the new cell. Let me know if you want me to email the changes to you!!! Thanks again for such a GREAT grid (when I was having problems I looked at some others grids... but your grid is so much better, feature packed and easy to use!!!!!!!) -Raymond
inserted: 2011-01-28 21:39:17   Reply...
From: tk
I think better solution is to add: if not (goAlwaysShowEditor in FOptions) then FlagClear(cGF_EditorModeActive); in SelectionChanged method right at the beginning of the block: if (sfMustUpdate in Flags) and not GridRectEqual(FSelection, NewSelection) then begin //... add here. I've fixed it for next patch.
inserted: 2011-01-19 15:16:17   Reply...
From: JanisT
Hallo! Is it posible to do this: RowCount = 1; FixedRows = 1; I need to have header with no data, if there is no data.
inserted: 2011-01-20 13:59:11   Reply...
From: tk
This is not possible yet. I always keep empty line if I have no data.
inserted: 2011-04-15 09:06:55   Reply...
From: marmore
So when i want add the first row to an empty dataset i cannot know columns names...
inserted: 2011-01-16 08:26:20   Reply...
From: Raymond
I have finally had a chance to test out kgrid and am very happy with it!!! Thank you! To change the background color, it appears that I have to change the Canvas.Brush.Color directly ... is this correct or am I missing an easier way> Many thanks, -Raymond
inserted: 2011-01-20 13:58:04   Reply...
From: tk
Change TKGrid.Color together with TKGrid.Colors.CellBkGnd.
inserted: 2011-01-20 18:18:02   Reply...
From: Raymond
Sorry, I should have been more clear... I need to change the cell background based upon a condition... something like this: if (salesAmount > 10) then kgrid1.CellPainter.Canvas.Brush.Color:=clGreen else if (salesAmount > 5) then kgrid1.CellPainter.Canvas.Brush.Color:=clYellow else kgrid1.CellPainter.Canvas.Brush.Color:=clRed This works, but I was wondering if I should be handling this a different way...?
inserted: 2011-01-28 21:42:31   Reply...
From: tk
No this is possible only via kgrid1.CellPainter.Canvas.Brush.Color in OnDrawCell or cell class related method.
Older comments
My account
Top downloads
Recently modified

KControls Development Suite

by: tk

2010-11-08

KHexEditor

by: tk

2010-11-08

KGrid

by: tk

2010-11-08

KIcon

by: tk

2009-11-24

KGrid 1.3 released.

by: tk

2009-08-10

Recently inserted

KComponents as open source

by: tk

2011-04-16

Problem with comments and logins

by: tk

2010-01-29

KControls released

by: tk

2009-10-15

Working hard on KGrid update...

by: tk

2009-06-22

EMWD

by: tk

2007-12-03

No translation available

by: tk

2007-10-30