1. Technology
Send to a Friend via Email

Using the TDBGrid component

DBGrid to the Max

By

Contrary to most other Delphi data-aware controls, the DBGrid component has many nice features and is more powerful than you would have thought.

Pulling the maximum out of the TDBGrid Delphi component

Basic stuff
How to create a simple (BDE) database display form
General instructions for setting up a Table, DataSource and DbGrid component at design time in order to access the data encapsulated by a table component.

How to display only selected fields in a DbGrid
How use the Fields Editor to define a list of some of the fields in a table that are to be displayed in the Grid.

Making the Enter key work like a Tab key in a DBGrid
Enter (Shift+Enter) processing in DBGrid.

Prevent CTRL + DELETE in DBGrid
How to disable keyboard delete operation inside a DBGrid.

Get the line number of a selected row in a DBGrid
If you want to get the line number of a selected row in a DBGrid component, here's what to do...

Using two DGBrids for Master-Detail DB relationships
Using two TTable or TQuery descendats to create master-detail database entry forms.

Look and Feel
Adjusting DBGrid column widths automatically
Automatically fix the size of TDBGrid columns (at run-time) to fit the DBGrid width (remove the unfilled space at the right edge of the grid).

How to AutoFit the Columns in the TDBGrid
Adjusting Column Widths to Fit the Widest Entry in a DBGrid Column

How to Highlight Non-Focused DBGrid Selected Row
In scenarios where you have two DBGrid controls on the same form displaying data for a master-detail database relationshiplike Customer -> Orders, for a selected record/row in the "master" grid only related records are displayed in the "child" grid. As soon as the grid looses the focus, the selected row does no longer appear selected. Here's how to make the selected row appear as focused even when the DBGrid is not focused.

How to Store and Retrieve DBGrid's Columns Order and Visibility
If you allow a user to customize DBGrid's appearance at run time (Columns width and position), when the form is closed and reopened, all the user changes are lost. For a better user experience it would be ideal if your application could somehow store (and load when needed) all the changes the user has made to the Grid appearance. Here's how.

Coloring DBGrid
How to enhance the functionality of a TDBgrid component using colors (coloring rows, columns, cells - depending ona field value).

Drawing images in DBGrid
Here's how to place an image into a cell of a TDBGrid.

How to correctly use the mouse wheel in DBGrid
Mouse wheel behaves strangely with dbgrids - here's a fix.

Displaying and editing MEMO fiels
Here's how to show the contents of a MEMO (textual BLOB) field in a TDBGrid (and how to enable editing MEMO's).

Match column title alignments with field alignments in DBGrid
Here's how to match Column title alignement with field alignement.

Nifty stuff
DBGrid with MultiSelect
Multiple row selection in Delphi DBGrid - providing the ability to select multiple records within the grid.

Summing multiple selected rows in a DBGrid
With multiple row selection enabled in TDBGrid, here's how to display a sum of selected fields.

How to select all rows (records) in a DBGrid from code
When the DBGrid's Options property includes dgRowSelect and dgMultiSelect, users can select multiple rows in a grid. Here's how to select the entire DBGrid from code.

Sorting records in DBGrid by Clicking on Column Title
How to sort records in Delphi DbGrid by clicking on the column title. Plus: how to change the appearance of the selected column title to reflect the sort order. Even more: how to change the cursor when moving over the DBGrid column titles.

Accessing and managing MS Excel sheets with Delphi
How to retrieve, display and edit Microsoft Excel spreadsheets with ADO (dbGO) and Delphi. This step-by-step article describes how to connect to Excel, retrieve sheet data, and enable editing of data (using the DBGrid). You'll also find a list of most common errors (and how to deal with them) that might pop up in the process.

Geeky stuff
Highlighting Delphi's DBGrid Row On Mouse Hover
Need to highlight the row behind the mouse cursor in a DBGrid?

Selecting and highlighting a row in a DBGrid - "OnMouseOverRow"
Here's how to select (make active record) and highlight (change color, font, etc.) a row in a DBGrid as mouse moves around the grid.

How to get DBGrid's Cell coordinates
The code to show over what cell in a DBGrid the cursor is, and how to change the cursor over the tite bar.

Advanced stuff - Email Course
Adding components to a DBGrid - theory
How to place just about any Delphi control (visual component) into a cell of a DGBrid.

CheckBox inside a DBGrid
Editing boolean fields inside a DBGrid (using a TChekBox control).

DateTimePicker (calendar) inside a DBGrid
Place a drop down calendar into a cell of a DBGrid.

Drop down pick list inside a DBGrid - part 1
Editing lookup fields inside a DBGrid - using the PickList property of a DBGrid column.

Drop down list (DBLookupComboBox) inside a DBGrid - part 2
DBLookupComboBox inside a DBGrid (editing lookup fields).

Tricky stuff
Accessing protected members of a DBGrid
Example: accessing a DBGrid's RowHeights (protected) property.

Refresh a DBGrid without Loosing the Current Row Position

Drag and drop with DBGrid

How to focus a specific cell in a DBGrid

How to allow column resize but disable movement
Here's how to prevent columns from being moved (but allow resizing).

Exposing the OnClick event for a DBGrid
How to hack a DBGrid and surface the OnClick event.

What is being typed into the DBGrid?
You can see what is being typed into a TDBGrid by looking at the TInPlaceEdit control of the TDBGrid...

Third Party TDBGrid implementations

If you still don't find the DBGrid component powerful enough, here's the list of the best Data Aware Grid components available for Delphi. The TDBGrid component enhanced to maximum: Top DB Aware Grid Components

©2014 About.com. All rights reserved.