Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

DBGrid & CheckBox

Status
Not open for further replies.

levogiro

Programmer
Apr 30, 2001
50
BR
hi,

i have a numeric field and its value can be 0 or 1. i'd like to know how to put a checkbox on a grid based on this field (0 - checked; 1 - unchecked).

thanks.
 
Assuming you have a [tt]TTable[/tt] or [tt]TQuery[/tt] etc, you can use a [tt]tDBCtrlGrid[/tt], and attach your datasource.

Set up the number of rows, and drag a [tt]tDBCheckBox[/tt], and any other fields you need onto the top row.

In the properties of your [tt]tDBCheckBox[/tt] set the field property to your field. You can change the caption to reflect your data of course.
In the [tt]ValueChecked[/tt] and [tt]ValueUnchecked[/tt] properties set the values to 0 and 1 (as per your description above)

Hope that helps....

Chris ;-)
 
I always reckon that the inability of TDBGrid to display a checkbox is a shortcoming of Delphi.

Chris has one solution. If you don't want to use a TDBCtrlGrid, you can paint a checkbox onto a TDBGrid using OnDrawColumn cell and then trap OnClick to handle the changing. More than trivial, but certainly doable.

Have fun
Simon

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top