Delphi-Quellcode:
procedure TForm1.StringGrid1DrawCell(Sender: TObject; ACol, ARow: Integer;
Rect: TRect; State: TGridDrawState);
function CheckBox(Value: String): Cardinal;
begin
result:= DFCS_INACTIVE; // no Entry
if Value = 'true' then // Checked
result:= DFCS_BUTTONCHECK or DFCS_CHECKED
else if Value = 'false' then // not Checked
result:= DFCS_BUTTONCHECK;
if not Editing then
result:= result or DFCS_MONO; // no Editing
end;
begin
with TStringGrid(Sender) do
if (ACol in CheckBoxCols) and not (gdFixed in State) then begin
Canvas.FillRect(Rect);
InflateRect(Rect, -4, -4);
DrawFrameControl(Canvas.Handle, Rect,DFC_Button,
CheckBox(Trim(Cells[ACol, ARow])));
end; // if gdFixed in State
end;
OK, dann hier nur noch 'true' und 'false' gegen '1' und '0' tauschen, da dort nur die Zahl drinnen steht und nicht der Text.
oder
Delphi-Quellcode:
procedure TForm1.StringGrid1DrawCell(Sender: TObject; ACol, ARow: Integer;
Rect: TRect; State: TGridDrawState);
function CheckBox(Value: boolean): Cardinal;
begin
result:= DFCS_INACTIVE; // no Entry
if Value then // Checked
result:= DFCS_BUTTONCHECK or DFCS_CHECKED
else // not Checked
result:= DFCS_BUTTONCHECK;
if not Editing then
result:= result or DFCS_MONO; // no Editing
end;
var
b : boolean;
begin
try
with TStringGrid(Sender) do
if (ACol {in CheckBoxCols)} =1) and not (gdFixed in State) then begin
b := StrToBool(Trim(Cells[ACol, ARow]));
Canvas.FillRect(Rect);
InflateRect(Rect, -4, -4);
DrawFrameControl(Canvas.Handle, Rect,DFC_Button,CheckBox(b));
end; // if gdFixed in State
except
end;
end;
Dann ist es egal, ob '0' und '1' oder 'true' und 'false', da StrToBoll beides konvertieren kann..