简体   繁体   中英

DBGrid save cell color after OnCellClick (delphi, lazarus)

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!

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM