Fórum Me ajudem com Checkbox na Grid #505519
26/12/2014
0
procedure TfrmEnvSMS.gridTelefonesCellClick(Column: TColumn);
begin
with dmDados do
begin
CDSNumTel.Edit;
if CDSNumTelSEL.Value = False then
CDSNumTelSEL.Value := True
else
CDSNumTelSEL.Value := False;
CDSNumTel.Post;
end;
end;
procedure TfrmEnvSMS.gridTelefonesDrawColumnCell(Sender: TObject;
const Rect: TRect; DataCol: Integer; Column: TColumn; State: TGridDrawState);
var
Check: Integer;
R: TRect;
begin
with dmDados do
begin
//Desenha um checkbox no dbgrid
if Column.FieldName = 'SEL' then
begin
gridTelefones.Canvas.FillRect(Rect);
Check := 0;
if CDSNumTelSEL.Value = True then
Check := DFCS_CHECKED
else
Check := 0;
R:=Rect;
InflateRect(R,-2,-2); {Diminue o tamanho do CheckBox}
DrawFrameControl(gridTelefones.Canvas.Handle,R,DFC_BUTTON, DFCS_BUTTONCHECK or Check);
end;
end;
end;
Tenho um ClientDataSet com um Field do tipo Booleano chamado SEL.
Uso Delphi XE
Marlon Minotti
Curtir tópico
+ 0Posts
29/12/2014
Renato Rubinho
Deixa a cor do texto igual à cor da célula, ficando o texto "transparente".
procedure TfrmEnvSMS.gridTelefonesDrawColumnCell(Sender: TObject;
const Rect: TRect; DataCol: Integer; Column: TColumn; State: TGridDrawState);
var
Check: Integer;
R: TRect;
begin
with dmDados do
begin
//Desenha um checkbox no dbgrid
if Column.FieldName = 'SEL' then
begin
// Deixa a cor do texto igual à cor da celula, ficando o texto "transparente"
gridTelefones.Canvas.Font.Color := gridTelefones.Canvas.Brush.Color;
// ####
gridTelefones.Canvas.FillRect(Rect);
Check := 0;
if CDSNumTelSEL.Value = True then
Check := DFCS_CHECKED
else
Check := 0;
R:=Rect;
InflateRect(R,-2,-2); {Diminue o tamanho do CheckBox}
DrawFrameControl(gridTelefones.Canvas.Handle,R,DFC_BUTTON, DFCS_BUTTONCHECK or Check);
end;
end;
end;
Abraççç,
rrubinho
Gostei + 0
29/12/2014
Marlon Minotti
Gostei + 0
29/12/2014
Marlon Minotti
Gostei + 0
30/12/2014
Marlon Minotti
gridTelefones.DefaultDrawDataCell(Rect, gridTelefones.columns[datacol].field, State);
Porém o texto não fica transparente totalmente, ele fica com alguns riscos de cor. como resolver?
Gostei + 0
30/12/2014
Renato Rubinho
Dá uma olhada nesse link Checkbox - DBGrid
Gostei + 0
30/12/2014
Jiraya San
dbgDados.Canvas.Font.Color := clWindow; dbgDados.Canvas.Brush.Color := clWindow; dbgDados.Canvas.FillRect(Rect);
Gostei + 0
30/12/2014
Marlon Minotti
Gostei + 0
30/12/2014
Marlon Minotti
Gostei + 0
Clique aqui para fazer login e interagir na Comunidade :)