Código
para colocar a figura do check, é só colocar um ImageList1, e adicionar nele as figuras do Check e do X, tipo confirmar e cancelar, feito isso crie um campo boleano para receber os valores para modificar a figura no grid: essa procedure pinta o Dbgrid com um checkbox}
procedure TForm1.DBGrid1DrawColumnCell(Sender: TObject; const Rect: TRect;
DataCol: Integer; Column: TColumn; State: TGridDrawState);
var
R: TRect;
begin
{pinta checkbox}
if Column.Field = ClientDataSet1ATIVO then
begin
DBGrid1.Canvas.FillRect(Rect);
ImageList1.Draw(DBGrid1.Canvas, Rect.Left + 10, Rect.Top + 1, 0);
if ClientDataSet1ATIVO.AsBoolean then
ImageList1.Draw(DBGrid1.Canvas, Rect.Left + 10, Rect.Top + 1, 2)
else
ImageList1.Draw(DBGrid1.Canvas, Rect.Left + 10, Rect.Top + 1, 1);
end;
end;
{essa daqui permite que o usuário clique com o mouse fazendo o checkbox mudar a figura.}
procedure TForm1.DBGrid1CellClick(Column: TColumn);
begin
if Column.Field = ClientDataSet1ATIVO then
begin
ClientDataSet1.Edit;
ClientDataSet1ATIVO.AsBoolean := not ClientDataSet1ATIVO.AsBoolean;
end;
end;
{essa daqui permite o grid ficar em modo edição para modificar a figura}
procedure TForm1.DBGrid1ColEnter(Sender: TObject);
begin
if DBGrid1.SelectedField = ClientDataSet1ATIVO then
DBGrid1.Options := DBGrid1.Options - [dgEditing]
else
DBGrid1.Options := DBGrid1.Options + [dgEditing];
end;
Planeta Delphi - www.planetadelphi.com.br - Todos os direitos reservados | Copyright 2001-2009