![dbgrid component delphi dbgrid component delphi](http://www.x-files.pl/images/styles7/large/Classic.png)
- #Dbgrid component delphi how to#
- #Dbgrid component delphi 32 bit#
- #Dbgrid component delphi code#
- #Dbgrid component delphi professional#
How to change the colour luminance or brightness.How to write on a canvas with a rotated font.Draw rich text transparently onto the canvas of a.
#Dbgrid component delphi 32 bit#
![dbgrid component delphi dbgrid component delphi](http://www.bergsoft.net/uploads/news/03-01-06/treecolumn.gif)
The improvement over the previous version is in the usage of the fieldname as indexname instead of the caption. Also, column resizing would be a nice added touch. It would be nice if clicking on a column a second time would reverse the sort order.
![dbgrid component delphi dbgrid component delphi](http://i1.wp.com/tech-story.net/wp-content/uploads/fig13_13.jpg)
There is a lot of room for improvement however. That's it! When the column is clicked, the Table's IndexName property is set to the same as the HeaderControl's caption. Procedure TForm1.HeaderControl1SectionClick(HeaderControl: THeaderControl The HeaderControl's OnSectionClick method should be as follows: When the HeaderControl is clicked, we need to turn on the correct index for the Table. After we are all done, we close the table, set Exclusive off and reopen then table. The creation of these indexes is why we had to open the table in Exclusive mode. This means that non-indexed columns will not respond to mouse clicks. We catch this exception and turn off the ability to click that column.
![dbgrid component delphi dbgrid component delphi](http://www.bergsoft.net/uploads/news/04-16-15/nxpagecontrol6.png)
When it tries to index on these fields, it will generate an exception. This step is in a try.finally structure because there are some fields that cannot be indexed (Blobs & Memos for example). The name of the index will be the same as the columns title. We are going to create an index for each column in the DBGrid. If you need resizeable columns, you will need a bit more code, and I wanted to keep this short and sweet. This will prevent the column from being resized. We also set the HeaderControl's MinWidth and MaxWidth properties to the same as the column width. We loop through the DBGrid columns, and for each one we copy over the column's caption and width. For each one we add, we will be giving it the same text as the caption of that column in the DBGrid. Next we need to make sure the Table is opened for Exclusive use (no other users can be using it). This will be a blank column that is the same width as the Grid's status area on the left. Then, we add a column to the HeaderControl and set its width to 12. Since the THeaderControl will be taking the place of the Grid's column headers, we first remove (set to False) the dgTitles option in the DBGrid's Options property. Procedure TForm1.FormCreate(Sender: TObject) ĭBGrid1.Options := DBGrid1.Options. DoubleClick on Form1's OnCreate event and enter the following code:
#Dbgrid component delphi code#
his will be done in code in the Form's FormCreate method. Now we need to setup the THeaderControl component to look like the DBGrid's column headers. Set Table's Active property to False in case it has been turned on. Set the DataSource's DataSet property to point at Table1 and the DBGrid's DataSource property to point to DataSource1. Set the Tables DatabaseName property to DBDEMOS and its TableName to EVENTS.DB. Next, add a TTable, and TDataSource component. Now drop a DBGrid on the form and set its Align property to alClient. It will automatically align to the top edge of the form. Here is how it is done:įirst, start a new application. The key is to connect the THeaderControl to the DBGrid. It can detect clicks on its individual panels, and the panels even go up and down when pressed (like a button). THeaderControl is a component that comes in Delphi 2.0 and provides the basic functions that we want. What we need is a way to make the column headers clickable. It does provide an OnDoubleClick, but this really doesn't work too well. It has no OnClick or OnMouseDown events, so it really was not designed to capture this kind of input. The key hurdle in this problem is the DBGrid itself. Although what is proposed here is not the best way to accomplish this, it is a fairly simple way to mimic the same behavior.
#Dbgrid component delphi professional#
Many professional applications will display data in grid fields and allow you to sort on any one of the columns simply by clicking on the column header.