Click here to Skip to main content
15,888,313 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
I am trying to add a checkbox to a DBGrid for displaying data. Here is an extract from the code I have trouble with. Not sure what the problem is or how to describe it either. Read the comment in the code for the problem explanation please:

Delphi
procedure TForm1.DBGrid1DrawColumnCell(Sender: TObject; const Rect: TRect; DataCol: Integer; Column: TColumn; State: TGridDrawState);
  
const IsChecked : array[Boolean] of Integer = 
      (DFCS_BUTTONCHECK, DFCS_BUTTONCHECK or DFCS_CHECKED);
var
  DrawState: Integer;
  DrawRect: TRect;
begin
  if (gdFocused in State) then
  begin
    if (Column.Field.FieldName = DBCheckBox1.DataField) then
    begin
     DBCheckBox1.Left := Rect.Left + DBGrid1.Left + 2;
     DBCheckBox1.Top := Rect.Top + DBGrid1.top + 2;
     DBCheckBox1.Width := Rect.Right - Rect.Left;
     DBCheckBox1.Height := Rect.Bottom - Rect.Top;

     DBCheckBox1.Visible := True;
    end
  end
  else
  begin
    if (Column.Field.FieldName = DBCheckBox1.DataField) then
    begin
      DrawRect:=Rect;
      InflateRect(DrawRect,-1,-1);

      DrawState := ISChecked[Column.Field.AsBoolean]; //Here is the problem... I use Embarcadero RAD Studio XE2 and am new to Delphi. Not sure if this line of code is only relevent to Delphi7. Could more light on this perhaps be shed? Maybe direct me to an appropriate source so I can use this code in my program? In my  RAD studio, 'ISChecked' is underlined in RED and is said to be an undeclared identifier... What am I doing wrong? Am I missing something?

      DBGrid1.Canvas.FillRect(Rect);
      DrawFrameControl(DBGrid1.Canvas.Handle, DrawRect, DFC_BUTTON, DrawState);
    end;
  end; 
end;


Here is the link to the site I obtained this code from:

http://delphi.about.com/od/usedbvcl/l/aa082003a.htm[^]

Any suggestions would be greatly appreciated!
Thanx
Posted
Comments
[no name] 2-Jul-12 14:24pm    
I am not at all and expert in Delphi or Pascal. But ISChecked would seem to me to be unusual. Try IsChecked instead and see what happens. If not, then good luck!
Sergey Alexandrovich Kryukov 2-Jul-12 14:51pm    
When I worked with Delphi and all the time before, Pascal was case-insensitive...
--SA
[no name] 2-Jul-12 14:57pm    
Ah, thanks. Now I know. Thought it was worth a shot.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900