Jump to content

StringGrid cell style not working.


rgreat

Recommended Posts

I managed to design this grid, but I can not set cell text alignment.

image.png.f488d396d1d81df41c2cc191181352ce.png

I cannot seems to currectly use Attribs.Style SG0DrawCell event.

procedure TMain.SG0DrawCell(Sender: TObject; ACol, ARow: Integer; var Value: string; Attribs: TUniCellAttribs);
begin
  Attribs.Font.Size:=10;
  Attribs.Font.Style:=[fsBold];

  if ARow=0 then begin
    Attribs.Font.Color:=clBlack;
  end else begin
    if ACol=0 then begin
      Attribs.Font.Color:=rgb(0,32,96);
      Attribs.Color:=rgb(152,152,152);
    end else begin
      Attribs.Font.Color:=clBlack;
      Attribs.Color:=rgb(213,213,213);
    end;
    Attribs.Style.Style := 'text-align: center;'; // <- this like breaks all previous settings and does not seems to do anything itself.
  end;

Can someone give out example of setting cell styles through OnDrawCell event?

I would also like to know how to disable cell selection rectangle drawing.

Link to comment
Share on other sites

Workaround for someone who might be interested:

.mygrid div table td div{
    text-align: center !important;
}

.mygrid div table td:nth-child(1) div{
    text-align: left !important;
}

.mygrid div table:nth-child(1)  td div{
    text-align: center !important;
}

.mygrid div table:nth-child(2)  td:nth-child(1) div{
    text-align: right !important;
}

And set  grid LayoutConfig.Cls to 'mygrid'.

image.png.d4edafb91d5271a0a241009f509d73b1.png

  • Like 1
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...