Recent

Author Topic: iterate dbgrid, color finished row  (Read 833 times)

musicto

  • Newbie
  • Posts: 3
iterate dbgrid, color finished row
« on: October 28, 2024, 11:14:58 am »
Hi,

in my procedure i move through my dbgrid selection like this:

Code: Pascal  [Select][+][-]
  1.  
  2. for  z := 0 to frm1.dbg2EA.SelectedRows.Count - 1 do
  3. begin
  4. frm1.dbg2EA.DataSource.DataSet.Bookmark := frm1.dbg2EA.SelectedRows[z];        
  5. dosomeworkwiththerecord;
  6. dosomemoreworkwiththerecord;
  7. end;
  8.  

After i have finished my work for the selected record, i want to color the row before i move to the next one.
So the User can easy see the progress of the work.

Cant be that hard, but can someone help me please?

Sascha

Handoko

  • Hero Member
  • *****
  • Posts: 5425
  • My goal: build my own game engine using Lazarus
Re: iterate dbgrid, color finished row
« Reply #1 on: October 28, 2024, 03:43:57 pm »
I haven't tried to color a cell or a row in TDBGrid. But it can be done easily in TStringGrid. TDBGrid has OnPrepareCanvas event, so it should be able to be done as in TStringGrid too.

I have 2 demos showing how to color a cell/row in TStringGrid. Click the link below, then go to User Interface section. There you can find Searchable StringGrid:
https://wiki.freepascal.org/Portal:HowTo_Demos

Soner

  • Sr. Member
  • ****
  • Posts: 319
Re: iterate dbgrid, color finished row
« Reply #2 on: October 29, 2024, 09:39:13 pm »
You have to change lazarus\lcl\dbgrids.pas for this:
Code: Pascal  [Select][+][-]
  1. TCustomDBGrid=class(TCustomGrid)
  2. // ..
  3. public
  4. //...
  5. property DrawingActiveRecord: Boolean read FDrawingActiveRecord; //for highlighting in PrepareCanvas
  6. end;
  7.  

Then in your programm for TDBGrid.OnPrepareCanvas-Event:
Code: Pascal  [Select][+][-]
  1. procedure TForm1.DBGrid1PrepareCanvas(sender: TObject; DataCol: Integer;   Column: TColumn; AState: TGridDrawState);
  2. begin
  3.   if DBGrid1.DrawingActiveRecord then begin
  4.     //put your code i.e. change row color
  5.     DBGrid1.Canvas.Brush.Color:=clRed;
  6.     DBGrid1.Canvas.Font.Color:=clWhite;
  7.  end;
  8.  

musicto

  • Newbie
  • Posts: 3
Re: iterate dbgrid, color finished row
« Reply #3 on: October 30, 2024, 07:30:43 am »
Handokos Post gave me the hint and i solved it.
So all finished Records are colored.

Thank you,

Sascha

 

TinyPortal © 2005-2018