Article View: borland.public.cppbuilder.database.ado
Article #2199Re: How to place check box on a dbgrid column
From: Daryl
Date: Mon, 13 Oct 2003 09:27
Date: Mon, 13 Oct 2003 09:27
111 lines
4562 bytes
4562 bytes
Hi
I had this problem and with some help of some Delphi code solved it. It was
quite a while ago but I am sure you will be able to work out how it is done
using the code below.
The trick is that you use an API to draw the box and check it if the value
is true.
Regards
Daryl
//--------------------------------------------------------------------------
-
void __fastcall TfrmMain::dbgHistoryCellClick(TColumn *Column)
{
// Used to only allow the Waived Fee value if the item has NOT been
returned
// and there is a late fee.
if (Column->FieldName == "LateFeeWaived") {
String LFID;
float lateFee;
LFID =
dmVideoOne->dsHistory->FieldByName("LateFeeTransactionID")->AsString;
lateFee = dmVideoOne->dsHistory->FieldByName("LateFee")->AsFloat;
if (LFID.Length() == 0 && lateFee > 0.0) {
Column->ReadOnly = false;
saveBoolean();
}
else
Column->ReadOnly = true;
}
}
//--------------------------------------------------------------------------
-
void TfrmMain::saveBoolean(void)
{
dbgHistory->SelectedField->DataSet->Edit();
dbgHistory->SelectedField->AsBoolean =
!dbgHistory->SelectedField->AsBoolean;
dbgHistory->SelectedField->DataSet->Post();
}
//--------------------------------------------------------------------------
-
void __fastcall TfrmMain::dbgHistoryDrawColumnCell(TObject *Sender,
const TRect &Rect, int DataCol, TColumn
*Column,
TGridDrawState
State)
{
// Used to change the colour of the Grid's cell's font
if (Column->FieldName == "Paid") {
if (Column->Field->AsString == "Yes") {
dbgHistory->Canvas->Font->Color = clLime;
}
else if (Column->Field->AsString == "No") {
dbgHistory->Canvas->Font->Color = clRed;
}
else {
dbgHistory->Canvas->Font->Color = clWindowText;
}
}
else if (Column->Field->DataType == ftBoolean) {
const int ctrlState[2] = {DFCS_BUTTONCHECK, DFCS_CHECKED};
TRect chkBoxOutline;
dbgHistory->Canvas->FillRect(Rect);
chkBoxOutline.Left = Rect.Left+2;
chkBoxOutline.Right = Rect.Right-2;
chkBoxOutline.Top = Rect.Top+2;
chkBoxOutline.Bottom = Rect.Bottom-2;
DrawFrameControl(dbgHistory->Canvas->Handle,
&chkBoxOutline,
DFC_BUTTON,
ctrlState[Column->Field->AsBoolean]);
return;
}
dbgHistory->DefaultDrawColumnCell(Rect, DataCol, Column, State);
}
//--------------------------------------------------------------------------
-
void __fastcall TfrmMain::dbgHistoryColEnter(TObject *Sender)
{
if (dbgHistory->SelectedField->DataType == ftBoolean) {
fOrigOptions = dbgHistory->Options;
dbgHistory->Options = fOrigOptions >> dgEditing;
}
}
//--------------------------------------------------------------------------
-
void __fastcall TfrmMain::dbgHistoryColExit(TObject *Sender)
{
if (dbgHistory->SelectedField->DataType == ftBoolean) {
dbgHistory->Options = fOrigOptions << dgEditing;
}
}
//--------------------------------------------------------------------------
-
"Murthy" <murthy.c.l.n@mphasis.com> wrote in message
news:3f82be97$1@newsgroups.borland.com...
>
> I have a boolean field in a table. I am using ADO connection and dbgrid. I
am planning to use a check box for this column. I am not finding any way to
do this. It is easy to put a dropdown box but not a any cehckbox.
>
> I need to add, edit, delete and update using this cehcbox, dbgrid and ado.
>
> Kindlly help
>
> Murthy
Technical Details
Message-ID:
<3f8a6de7@newsgroups.borland.com>Path:
arc1-ca.pugleaf.net!archiver1.google.com!news2.google.com!news.maxwell.syr.edu!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mailReferences:
<3f82be97$1@newsgroups.borland.com>Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 10698b,ce28aaff1d32d6ed X-Google-Attributes: gid10698b,public X-Google-ArrivalTime: 2003-10-13 02:39:53 PST From: "Daryl" <stockd@tpg.com.au> Newsgroups: borland.public.cppbuilder.database.ado References: <3f82be97$1@newsgroups.borland.com> Subject: Re: How to place check box on a dbgrid column Date: Mon, 13 Oct 2003 19:27:41 +1000 Lines: 113 X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 6.00.2462.0000 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2462.0000 NNTP-Posting-Host: 202.7.180.150 Message-ID: <3f8a6de7@newsgroups.borland.com> X-Trace: newsgroups.borland.com 1066036711 202.7.180.150 (13 Oct 2003 02:18:31 -0700) Path: arc1-ca.pugleaf.net!archiver1.google.com!news2.google.com!news.maxwell.syr.edu!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail