0
votes

Sorry for my English. I have some table (from datasource->mssql server->views), and i need to delete/hide/assign text color= white/any other things for clicked cells in DBGrid. Like: i clicked cells->cells font=white(or clicked .text:=''/etc..);save;clicked next cells; repeat. I try do like this:

procedure TForm1.DBGrid1DrawColumnCell(Sender: TObject;
  const Rect: TRect; DataCol: Integer; Column: TColumn; State: TGridDrawState);
begin
if gdSelected in State
  then begin
    with  DBGrid1.Canvas do
    begin
        Brush.Color:=clWhite;
        Font.Color:=clWhite;
        FillRect(Rect);
    end;
    end;
end;

But it works for only 1 cell: when i click next cells the color becomes standart (like in another cells in DBGrid) for the previous cell. How i can save cell color for all clicked cells? //Complicated by the fact that I do not know much about Delphi Thanks!

1
Can you tell us why you want to chang the color ? and what you mean by i need to delete/hide/assign ? what you want to achieve`?Ilyes
I need to hide the cells that have been clicked from DBGridPetyaVasechkin
You want to hide a column or just specifique cells?Ilyes
Just specifique cells. Values in cpecifed cells.PetyaVasechkin

1 Answers

0
votes

I believe it is because you are using if gdselected in state. Only one cell at a time is selected so only that cell is drawn using your blanking code.

You need to set a property when a cell is clicked (say set tag = 1, or something like that), then check that tag along the lines of "if Sender.Tag > 0 then . I believe the sender is the cell itself and so something like TControl( Sender ).tag or some other appropriate cast will get you what you want.