Friend, I created a Clientdataset with 2 fields, a string calling name and another integer called selector.
Adding some records in formcreate
ClientDataSet1.Open;
ClientDataSet1.Append;
ClientDataSet1Nome.AsString := 'Stack';
ClientDataSet1Selecao.AsString := '1';
ClientDataSet1.Append;
ClientDataSet1Nome.AsString := 'OverFlow';
ClientDataSet1Selecao.AsString := '0';
ClientDataSet1.Post;
In the grid Drawcolumncell event put the following code:
var
Check: Integer;
R: TRect;
begin
inherited;
if ((Sender as TDBGrid).DataSource.Dataset.IsEmpty) then
Exit;
if(UpperCase(Column.FieldName) = 'SELECAO') then
begin
TDBGrid(Sender).Canvas.FillRect(Rect);
if (TDBGrid(Sender).DataSource.DataSet.FieldByName('selecao').AsInteger = 1) then
Check := DFCS_CHECKED
else
Check := 0;
R := Rect;
InflateRect(R, -2, -2);
DrawFrameControl(TDBGrid(Sender).Canvas.Handle, R, DFC_BUTTON,
DFCS_BUTTONCHECK or Check);
end;
end;
In the Grid Colenter
if UpperCase(TDBGrid(Sender).SelectedField.FieldName) = 'SELECAO' then
TDBGrid(Sender).Options := TDBGrid(Sender).Options - [dgEditing]
else
TDBGrid(Sender).Options := TDBGrid(Sender).Options + [dgEditing];
In the Cellclick of the grid
if(UpperCase(Column.FieldName) = 'SELECAO') then
begin
ClientDataSet1.Edit;
if(ClientDataSet1.FieldByName('Selecao').AsInteger = 1) then
begin
ClientDataSet1.FieldByName('Selecao').AsInteger := 0;
end
else
begin
ClientDataSet1.FieldByName('selecao').AsInteger := 1;
end;
ClientDataSet1.Post;
ShowMessage(ClientDataSet1.FieldByName('selecao').AsString);
end;
In the Gettext field event that will be the Clientdataset check (Select)
Text := EmptyStr;
After I tested I realized I just need the event
DrawColumnCell
because I won’t need to change the image on Click. Thank you very much for the Help.– Edu Mendonça
You know how to mark the desired items only with the mouse?
– ProsTecnologia