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
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
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.6.zip1.6624Delphi 6+, Lazarus 0.9.29(SVN#21827)+, C++Builder 2007+column/row/grid autosizing and many other improvements and bugfixes
kgrid_1.5.zip1.51559Delphi 6+,Lazarus 0.9.29(SVN#21827)+tiny modifications due to releasing KControls
kgrid_1.5beta.zip1.5 beta148Delphi 6+,Lazarus 0.9.29(SVN#21827)+printing and previewing (Lazarus only Win32), drawing thumbnail/image cell
kgrid_1.4.zip1.4538Delphi 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.3522Delphi 6+,Lazarus 0.9.26+doesn't need JCL, port to Lazarus(Win32), ThroughClick property, text output attributes.
KGrid_1.3beta.zip1.3 beta138Delphi 6+Column/row visibility, more sorting styles & other fixes.
KGrid_1.2.zip1.22428Delphi 6+Update for Delphi 2009, minor fixes, OnChanged event, documentation update
22.10. hotfix for Delphi6-7
KGrid11.zip1.11398Delphi 6 till 2007Sorting interface, cell clipping and double buffering, TKGridCellPainter class, another improvements and fixes, documentation update
KGrid10.zip1.0990Delphi 6 till 2007Index mapping, demo, finished documentation, many bugfixes and improvements
KGrid09.zip0.9240Delphi 6 till 2007Initial release

Screenshots (click the images to enlarge)

Version 1.5 screenshots

 
Extensive support for printing and previewingPreview window detail

Version 1.4 screenshots

 
Main demo in Delphi/Windows VistaSimple database demo in Delphi/Windows XP
 
Advanced header demo in Lazarus/Linux (GTK2)Main demo in Lazarus/Linux (GTK2)

Version 1.1 screenshots

 
Sorting of rowsSorting of both rows and columns
 
TKGridAttrTextCell demoEntering new rows into previously sorted rows is simple

Version 1.0 screenshots

 
Simple KGrid demonstration programColumn moving demonstration - this style is done via layered windows
 
Range selection, though focused cell is still editableDisabled grid
 
Arbitrary TWinControl descendant can be used as inplace editorDocumentation preview
 

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

Search in comments: 
inserted: 2010-07-26 09:30:44   Reply...
From: Silver
Hello, Thank you for your great component KGrid! I have a question: is it possible to change scale (zoom) of a grid? I use KGrid to display some schema and when there are a lot of cols/rows i need scaling. Is it possible? Thanks.
inserted: 2010-07-26 11:00:52   Reply...
From: tk
Scaling is supported only for the printing/previewing but not in the real view. Although the KGrid painting chain supports scaling via window/viewport transformations, there is no such support for scrollbar adjustments, mouse point conversions etc. I recommend you to write your own function that simply scales column widths and row heights. Use LockUpdate/UnlockUpdate pair for this as shown in the demo. Then use the current scale in OnDrawCell for your cell fonts, images etc.
inserted: 2010-07-06 14:43:23   Reply...
From: skrzat
When I add OnDrawCell event (even empty procedure), cells are invisible and often black. When I edit single cell then I see this cell's content, but when I exit editing, cell is invisible again. When I remove OnDrawCell event everything is OK again (visible) I use Lazarus 0.9.29 FPC 2.5.1 SVN 26140
inserted: 2010-07-09 11:12:19   Reply...
From: tk
I don't experience this in Lazarus but I use different version. Please try playing around with DoubleBuffered, goDoubleBufferedCells, goClippedCells and taClip. Which widget set makes the problem?
inserted: 2010-06-29 12:16:43   Reply...
From: Javor
Hi. Today I've downloaded latest build of TKGrid. Yes, some bugs I saw before are fixed now. But as I tried to compile my project there was an error in CellPainter.DrawCellText. On the older version it took parameters (TRect, hAlign, vAlign, ..., color). Now it takes only TRect as a parameter. Why did you change this method? And where shall I set the desired parameters, such as Text Alignment, Cell Color, etc.?
inserted: 2010-06-29 13:46:44   Reply...
From: tk
I forgot to keep the old method for backward compatibility. You can now use cellpainter properties like HAlign, VAlign, Attributes etc. to modify text output. The same for cell graphic via Graphic... properties.
inserted: 2010-06-29 13:05:20   Reply...
From: Javor - a reply to myself
Anyway - just for compatibility reasons with version 1.5 and below I've added the following code: interface procedure DrawCellText(ARect: TRect; AHAlign: TKTextHAlign; AVAlign: TKTextVAlign; AHPadding, AVPadding: Integer; const AText: {$IFDEF STRING_IS_UNICODE}string{$ELSE}WideString{$ENDIF}; ABackColor: TColor; Attributes: TKTextAttributes); overload; virtual; implementation procedure TKGridCellPainter.DrawCellText(ARect: TRect; AHAlign: TKTextHAlign; AVAlign: TKTextVAlign; AHPadding, AVPadding: Integer; const AText: {$IFDEF STRING_IS_UNICODE}string{$ELSE}WideString{$ENDIF}; ABackColor: TColor; Attributes: TKTextAttributes); begin Include(Attributes, taFillRect); DrawAlignedText(FCanvas, ARect, FHAlign, FVAlign, FHPadding, FVPadding, AText, FBackColor, Attributes); end; If you like you can use the original code before drawing part: if FFillCellBackground then Include(Attributes, taFillRect) else Exclude(Attributes, taFillRect); Regards, Javor
inserted: 2010-06-05 14:58:57   Reply...
From: Wirya
How to install in delphi 5?
inserted: 2010-06-26 00:08:38   Reply...
From: Lucas
I made some modifications to source code - now it works with Delphi 5(include some files from project JEDI in times when it compiled in Delphi 5). http://cid-28c38c52c8760273.office.live.com/self.aspx/.Public/kgridDelphi5.zip It is quick fixed for Delphi 5 (e.g. compilators directives are doubled... and need to be removed/merged with kcontrols.inc and jedi.inc). PS first you have to compile KGrid_D5R.dpk then KGrid_D5.dpk (and install KGrid_D5.dpk). FIXED bug that TKPrintPreviewForm hadnt TKPrintPreview on the form (.dfm). For Delphi 6 and up/Lazarus 0.9.29 use orginal files from www.tkweb.eu. Maybe author of this component will include Delphi 5 as standard... It will need some more time but it is affordable.
inserted: 2010-06-01 08:49:21   Reply...
From: Javor
Hello. Found a bug in TKGrid - if FixedCols is 0 /zero/ an exception is raised concerning ColWidths at runtime. If however FixedCols is 1 /just for example/ the exception is not raised.
inserted: 2010-06-01 09:29:35   Reply...
From: tk
This has been fixed already for next release.
inserted: 2010-06-01 09:56:46   Reply...
From: Javor
When is the next release expected? Thanks in advance Regards, Javor
inserted: 2010-06-01 11:39:02   Reply...
From: tk
I thought I make a release with all the new capabilities like filters etc but I have absolutely no time to complete that now. I'll release my current as is status with many important hotfixes in few days.
inserted: 2010-06-26 08:52:32   Reply...
From: Lucas
Can you reproduce closer the bug with FixedCol = 0 ? Or it already been fixed ? The same for combo box not showing its contents...
inserted: 2010-06-26 23:13:45   Reply...
From: tk
I don't have any such problems with kgrid now - just try the new release.
inserted: 2010-06-26 23:40:16   Reply...
From: Lucas
Thanks. Things to do: - get the columns property editor as same in TDBGrid (maybe i will work this out);
inserted: 2010-04-16 17:35:59   Reply...
From: Suny
Hello, kgrid is great thanks. Dropped-down list from comboboxes is not visible. i did like you in example, but the kgrid resize it to cell-size, then list listbox-part of combobox is 2pixel high. How can i solve this problem? I use winxp-pro3 and delphi7 prof.
inserted: 2010-04-16 18:11:13   Reply...
From: Suny
I solved it. I commented out in KGrids.pas: Line 10720: //FEditor.Constraints.MaxHeight := Bottom - Top + 1;
inserted: 2010-03-31 15:46:40   Reply...
From: dedy
file 'kprintpreview.lrs' is not found when i want to compile kgrid 1.5 i use lazarus SVN 24308. any solution?
inserted: 2010-03-19 07:45:50   Reply...
From: kosthala
Hello, Is it possible if a column is of combobox type, to always show the combobox arrow on all column cells? Thanks in advance.
inserted: 2010-03-25 16:44:11   Reply...
From: tk
Yes but you have to paint it OnDrawCell in similar way as CellPainter paints check boxes. I'm not sure a WinApi function exists to paint combo button shape for you...
inserted: 2010-03-14 10:30:05   Reply...
From: arbj
how is the text in the column header aligned, all the text in the headers are aligned to the left I need some to be at the left and some at the center and some at right. How can I do this ?? Apart from this the control works perfectly well Thank you for providing a useful component.....
inserted: 2010-03-25 16:40:55   Reply...
From: tk
You can do this in OnDrawCell event, use CellPainter.HAlign property.
inserted: 2010-02-20 17:48:10   Reply...
From: skrzat
Hi, Thanks for great component (KGrid). Is there a chance to add a footer (fixed row with ie. sum of columns)? Correct me if this already exists and I didn't notice that.
inserted: 2010-03-25 16:38:14   Reply...
From: tk
No.
inserted: 2010-02-13 21:44:16   Reply...
From: Lucas
Anytime i try to run my application i got 'Error reading DBGrid.ColWidths: Invalid property value.' (i simply added Table and DataSource components and setted DatabaseName to DBDEMOS and TableName to employee.db also Active to true). When i connected TKDBGrid with DataSource on design time everything works fine (the data is displayed on dbgrid) only after run i get error mentioned earlier.
inserted: 2010-02-26 21:55:43   Reply...
From: Lucas
I figured it out. All i have to do is to remove ColWidths declaration from lfm/dfm source file. Hope it help somebody BTW i managed to compile and run KGrid on delphi 5 (BUT IT WAS DONE AFTER CODE MODIFICATIONS).
inserted: 2010-02-01 10:17:41   Reply...
From: techie
Apologies for the multiple posts. IE8 advised errors, so I assumed it wouldn't be posted. It has been posted. Any comments? Regards
inserted: 2010-02-01 20:33:50   Reply...
From: tk
Maybe a good time to try Firefox?
inserted: 2010-02-01 10:13:21   Reply...
From: techie
Hello tk I have been recommended to try KGrid with Lazarus to overcome a problem I have. I am transferring data to grids so they can be searched for information. The grids are up to 50000 rows long, 15 columns wide, and contain 750000 cells. The data in the cells is upto 10-15MB. The programs crash when running under WinCE (but not under Win32) when approx 350000 cells are filled. I can reduce the amount of data (down to 1.5MB) and they still crash. However, if I limit the number of cells below 350000 then the programs are OK. I have tried downloading KGrid14.zip from your website but it will not download. I have tried a direct connection to http://www.tkweb.eu/zipfiles/468aaab053ec8/kgrid14.zip but that doesn't seem to exist, only 2 kgrid11.zip (the underscore is not accepted by your handler), which I assume is not your latest version. Can you advise whether you would expect memory (32MB per application available on Windows Mobile 6.5) or number of cells in grid to be limiting factors with your KGrid? If not, can you advise how to download KGrid1.4 please? Regards
inserted: 2010-02-01 20:46:41   Reply...
From: tk
I can download kgrid1.4 without problems (Opera, Firefox). I'm sorry but I deeply hate IE, I don't bother with IE problems. Direct link is .../7_kgrid_1.4.zip. Because of memory limit I'm not aware of any data amount limitation. But I know some users had similar problems with WinCE. There was simply not enough memory there for huge grids. Did you try virtual grid mode (goVirtualGrid) or at least the basic textual cell (TKGridTextCell) to reduce memory? TKGridAttrTextCell consumes a lot of memory!
inserted: 2010-01-29 18:48:17   Reply...
From: madhamster
Is there a way to sort numbers properly? KGrid sorts cells as text values so numbers are sorted like: 1 10 2 20 not like 1 2 10 20.
inserted: 2010-01-29 20:55:46   Reply...
From: tk
Use OnCompareCells event and e.g. CompareIntegers function.
inserted: 2010-01-30 01:26:41   Reply...
From: madhamster
Big thanx :)
inserted: 2010-01-27 15:59:04   Reply...
From: Alex
Hello, When you update your component?
inserted: 2010-01-27 21:27:08   Reply...
From: tk
Half February is my "internal deadline" but please don't take this for granted. I'm quite busy with other things now. Also I consider to split this package for free and paid (but cheap) versions where licensed users will get instant support, more often updates and extra features.
inserted: 2010-01-26 14:45:27   Reply...
From: DelphiDude
Hi, Is it possible to detect double-click event on cells? Thanks.
inserted: 2010-01-27 21:18:59   Reply...
From: tk
I made a simple fix for that. It will be available in next release.
inserted: 2008-07-29 10:34:54   Reply...
From: barfat
Greeting... I try to install KGrid in my win2000 , delphi 6 enterprise update pack 2 , so I choosed KGrid_D6.dpk to compiled , but I encountered "[Error]KGrids.pas(1704):Undeclared identifier:WM_THEMECHANGED" , What can I do for this ?!... Undefine USE_THEMES will works fine ?! Thanks ...
inserted: 2008-07-29 11:00:19   Reply...
From: barfat
forget to mention : I download jedi 1.100 , as "Necessary Packages" mentioned ~~ In KControls.inc , I saw the following : { Specifies if Windows XP theme support should be used (D7 or Themes.pas is needed) } {$DEFINE USE_THEMES} I am win2000 , D6 update pack 2 , no Themes.pas in my pc , so ... what can I do to use KGrid ?! Thanks ...
inserted: 2008-07-29 11:32:06   Reply...
From: tk
I know there is no XP theme support in Delphi 6. If you need XP support for Delphi 6 you must install it first. Basically you need Mike Lischke's themes.pas unit that became a part of Delphi 7 and later. Also you need to define the WM_THEMECHANGED constant somewhere. If you don't need XP support, please undefine the USE_THEMES clause and you should be able to compile KGrid without XP theme support.
inserted: 2008-08-04 13:09:26   Reply...
From: gm3h
Hi tk, I want to implement HideRows/HideCols and UnhideRows/UnhideCols procedure to your KGrid. Can you give me some hints? Thanks.....
inserted: 2008-07-16 02:07:18   Reply...
From: gkathire
Hello, Is it possible to make this a Dataaware grid ? I took the TDBDataGrid from http://www.torry.net/db/visible/db_grids/datagrid.zip and replaced the base class TStringGrid with TKGrid. With few edits (blindly removed some override functions) I was able to compile the code and the db aware demo given with that component worked fine(It has thrown some error when exiting the application). Can you please have a look at the TDBDataGrid and add support for db aware TKGrid ? Thanks, GKathire
inserted: 2008-07-16 09:19:09   Reply...
From: tk
Hi, to be honest, I wanted to ask somebody to do that. Because I never did databases with Delphi. I know it might be simple to understand but I never had the true reason to learn it (and a creation of a db aware control). If you can help I'll appreciate this. But please understand I'm very busy with other things right now so it might be only possible for me to publish this db aware control here at this time.
inserted: 2008-07-13 19:57:05   Reply...
From: Leonardo
Hi, I need to use the grid in Virtual mode, wich event I must override to set cell data in this mode? Leonardo M. Ramé http://leonardorame.blogspot.com
inserted: 2008-07-13 20:44:52   Reply...
From: tk
Obviously you set the goVirtualGrid option True. Then, you cannot access the Cell and/or Cells properties anymore.
inserted: 2008-07-13 20:59:35   Reply...
From: Leonardo
Yes, thanks. Can you give an example? there isn't an OnData event or similar.
inserted: 2008-07-13 22:39:55   Reply...
From: tk
Any OnData event makes no sense with KGrid's philosophy. I made quickly a simple example. Please send your email address at tk@tkweb.eu or put it here so that I can post it to you.
inserted: 2008-07-13 23:12:54   Reply...
From: Leonardo
I'd try to send, but I received a "failure notice"... Can you send me a the example to martinrame at yahoo dot com??
inserted: 2008-07-11 07:19:21   Reply...
From: Tony
Hi! Do you have a step by step document or manual about adding controls to KGrid? I want to fill the grid with TButtons, but not putting a Button on every cell, but only in some of them, such as cell[1,1], cell[3,5], cell[5,7] and cell[6,3]. I'm a newbie in Delphi and for me the demo is hard to understand. Thanks in advance!
inserted: 2008-07-12 16:24:23   Reply...
From: tk
KGrid can contain only 1 inplace editor at the same time. It is not ready to accept more child controls as this is not the purpose of KGrid. If you need the buttons to APPEAR in some cells persistently, you must do two things for these cells: 1)You need to paint a button frame in OnDrawCell via DrawFrameControl or DrawElement if XP themes are enabled. This contour will be shown if the cell is not selected. 2)You need to create a TButton in OnEditorCreate. This contour will be shown if the cell is selected and the button will react to mouse/keyboard events as usual. It is the same manner as with check boxes in the demo. I admit the demo is not the easiest to understand but it shows many features of KGrid.
inserted: 2008-07-10 18:01:08   Reply...
From: martin
Can you add an example of how to place persistent editors in the fixed cells?. I need this to create filters, I.E.: placing a TEdit in each column header. Martin.
inserted: 2008-07-12 15:31:02   Reply...
From: tk
Well, this feature is not implemented. Fixed cells are not allowed to have an inplace editor. However, an easy hotfix might be created if you need the inplace editor to be displayed in fixed cells, such as in any other selectable cell. If you need the editor to persist in the fixed cell, if will be necessary to paint the editor outline in OnDrawCell such as the demo does it with check boxes. Please let's communicate directly via tk@tkweb.eu about this feature.
inserted: 2008-06-16 09:53:36   Reply...
From: Martin
Unfortunately it is not possible to download from your site. I try to download kgrid11.zip from http://www.tkweb.eu/en/delphicomp/kgrid.html?action=download&par=480dfaa8efbe3 But the result is only the webpage . Thanks, Martin
inserted: 2008-06-16 10:32:18   Reply...
From: tk
You have possibly a blocked redirecting? Try a direct link instead: http://www.tkweb.eu/zipfiles/468aaab053ec8/2_kgrid11.zip
inserted: 2008-02-20 07:37:59   Reply...
From: Yogi Yang
Thanks for developing and distributing such a great control for free. I am basically a newbie in Delphi and have been searching for such a grid that is really a treat to us. I have tried Virtual TreeView but it is a bit hard to learn and use but yours is easier to learn and use.
inserted: 2008-02-02 20:32:44   Reply...
From: JChris
Great component :) Are you planning to add in the future JVCL components in the cells ? for example Jvspinedit and other edit components.
inserted: 2008-02-03 20:24:39   Reply...
From: tk
Hi, you can use any TWinControl descendant. I tried JvSpinEdit now and it works quite fine. You just need to write "AEditor := TJVSpinEdit.Create(nil);" in EditorCreate event handler.
inserted: 2008-02-03 22:02:31   Reply...
From: JChris
I still have a question, is the KGrid1EditorCreate event triggered when the cell/column is activated ? I'm asking you, because I want to add a combobox with images and if it's created and all images are loaded everytime the column is activated, it's not very good. IF yes, is there a workaround not to create each time the control ? Thanks
inserted: 2008-02-03 22:32:45   Reply...
From: tk
Well, the EditorCreate event is triggered always when the cell is activated. I think a workaround for this is to create the editor somewhere else, e.g. in FormCreate, and then assign this in KGrid1EditorCreate to AEditor and prevent destroying this editor in KGrid1EditorDestroy by setting AEditor to nil. I tried it now and it works fine.
inserted: 2008-02-03 21:50:11   Reply...
From: JChris
Thanks :) Works very well.
inserted: 2008-01-31 17:34:46   Reply...
From: meloun
Great tool this KGrid..thx.
inserted: 2008-01-25 16:04:06   Reply...
From: HMcG
Could you please post some sample code showing use of the Kgrid component - I would like to use it to create a grid with a column of checkboxes in column 1. Preferably with the ckeckboxes persisting evenn when the focus is on anothe cell. Is this possible? Thanks
inserted: 2008-01-26 17:22:12   Reply...
From: tk
Exactly this is included in the new demo It will be released along version 1.0 in few days, I think even tomorrow. Many improvements come along...
inserted: 2008-01-29 07:06:34   Reply...
From: HMcG
Thanks, this is excellent news. As a newbie to Delphi, it's been very educational to look through the Kgrid code - I still have a lot to learn! Thanks again for making this component available.
My account
Top downloads
Recently modified

KControls Development Suite

by: tk

2010-06-21

KGrid

by: tk

2010-06-21

KIcon

by: tk

2009-11-24

KHexEditor

by: tk

2009-10-15

KGrid 1.3 released.

by: tk

2009-08-10

Recently inserted

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

No translation available

by: tk

2007-10-30