Jump to content


Photo

How to draw a separator line in the grid


  • Please log in to reply
5 replies to this topic

#1 czbird

czbird
  • Members
  • 58 posts

Posted 21 April 2015 - 12:21 PM

Hello, I'd like the grid to automatically draw a separator / division line if a certain condition is met - for example when cell value changes in the first column.

Just that all the cells would be framed from their bottom on a particular row in the grid -- see attachment of an excel table.

 

Please advise.

Thanks in advance.

 

Example:

 

aaa 111 111

aaa 222 222

aaa 333 333

------------------ (line)

bbb 111 111

bbb 222 222

bbb 333 333



#2 Boki (Berg)

Boki (Berg)

    Boki (Berg)

  • Forum Admin
  • PipPipPipPipPip
  • 8,191 posts
  • Gender:Male

Posted 21 April 2015 - 06:26 PM

Hi,

 

Maybe if you set GridLinesStyle to lsHorizontalOnly and then inside OnCellColoring event set var GridColor parameter to desired color and for specific ARow.


boki@bergsoft.net | LinkedIn Profile
--
BergSoft Home Page: www.bergsoft.net
Users Section: users.bergsoft.net
Articles and Tutorials: help.bergsoft.net (Developers Network)
--
BergSoft Facebook page
--
Send us applications made with our components and we will submit them on: www.bergsoft.net/apps.htm. Link to this page will be also set on home page too.

#3 czbird

czbird
  • Members
  • 58 posts

Posted 22 April 2015 - 11:25 AM

when I added this code, then the grid gets constantly repainted and flickers...

 

procedure TFStatusSBL.StatusGridCellColoring(Sender: TObject; ACol,
  ARow: Integer; var CellColor, GridColor: TColor; CellState: TCellState);
var
  Field, PrevField: TField;
begin
  if (ARow > 0) then begin
    Field := StatusGrid.CellField[0, ARow];
    PrevField := StatusGrid.CellField[0, ARow - 1];

    if Assigned(Field) and (not Field.IsNull) and
       Assigned(PrevField) and (not PrevField.IsNull) then
    begin
      if (Field.AsString = PrevField.AsString) then
        GridColor := clBtnFace
      else
        GridColor := clBlack;
    end;
  end;
end;

 

Updating CellColor has the same problem...



#4 Boki (Berg)

Boki (Berg)

    Boki (Berg)

  • Forum Admin
  • PipPipPipPipPip
  • 8,191 posts
  • Gender:Male

Posted 24 April 2015 - 04:54 PM

Hi,

Sorry for delay. You are moving trough grid records while cell is painted. Try to access to the field directly since you are in same record anyway.
boki@bergsoft.net | LinkedIn Profile
--
BergSoft Home Page: www.bergsoft.net
Users Section: users.bergsoft.net
Articles and Tutorials: help.bergsoft.net (Developers Network)
--
BergSoft Facebook page
--
Send us applications made with our components and we will submit them on: www.bergsoft.net/apps.htm. Link to this page will be also set on home page too.

#5 czbird

czbird
  • Members
  • 58 posts

Posted 24 April 2015 - 05:15 PM

Hi, it does not work either. I used this code:

  if (ARow > 0) then begin
    s1 := StatusGrid.Cells[0, ARow];
    s2 := StatusGrid.Cells[0, ARow-1];

    if (s1 <> s2) then
      GridColor := clRed
    else
      GridColor := clBlue;
  end;

- The lines are not drawn in color at all

- It messes up coloring of active row, when the grid is clicked on

 

Can you please provide a working example?

Either use GridColor or CellColor, it does not matter to me.

 

Thanks.



#6 Boki (Berg)

Boki (Berg)

    Boki (Berg)

  • Forum Admin
  • PipPipPipPipPip
  • 8,191 posts
  • Gender:Male

Posted 24 April 2015 - 06:28 PM

Hi,

 

When cell is painted, active record is moved trough all visible rows and Field property of Column is used as value.

 

I suggest checking 1st image in this tutorial:

http://dn.bergsoft.n...quick-start.htm

 

s1 := StatusGrid.Columns[0].Field.AsString;
if s1 <> s2 then
begin
end;
s2 := s1; // <--- we remember s2 for next record.

 

I hope that this helps.


boki@bergsoft.net | LinkedIn Profile
--
BergSoft Home Page: www.bergsoft.net
Users Section: users.bergsoft.net
Articles and Tutorials: help.bergsoft.net (Developers Network)
--
BergSoft Facebook page
--
Send us applications made with our components and we will submit them on: www.bergsoft.net/apps.htm. Link to this page will be also set on home page too.




1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users