How to set the alignment of TRVTableItemInfo in cell

General TRichView support forum. Please post your questions here
Post Reply
wolf1860
Posts: 108
Joined: Sat Nov 21, 2015 2:04 am

How to set the alignment of TRVTableItemInfo in cell

Post by wolf1860 »

I insert a TRVTableItemInfo into a table cell,How to set its alignment? I want to set it on the right side of the cell.

Thanks a lot!
Sergey Tkachenko
Site Admin
Posts: 17236
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Re: How to set the alignment of TRVTableItemInfo in cell

Post by Sergey Tkachenko »

In TRichView, cells do not have horizontal alignment properties.
Align all paragraphs in the cell to the right.
wolf1860
Posts: 108
Joined: Sat Nov 21, 2015 2:04 am

Re: How to set the alignment of TRVTableItemInfo in cell

Post by wolf1860 »

How? The cell is empty before I insert a TRVTableItemInfo.
Sergey Tkachenko
Site Admin
Posts: 17236
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Re: How to set the alignment of TRVTableItemInfo in cell

Post by Sergey Tkachenko »

The cell is not really empty, it contains one empty text item.

This code inserts a table having all cells right-alignment:

Code: Select all

function GetParaStyleWithAlignment(Alignment: TRVAlignment; Style: TRVStyle): Integer;
var
  ParaStyle: TParaInfo;
begin
  ParaStyle := TParaInfo.Create(nil);
  ParaStyle.Alignment := Alignment;
  Result := Style.FindParaStyle(ParaStyle);
  ParaStyle.Free;
end;

...
var
  Table: TRVTableItemInfo;
  r, c, ParaNo: Integer;
begin
  ParaNo := GetParaStyleWithAlignment(rvaRight, RichViewEdit1.Style);
  Table := TRVTableItemInfo.CreateEx(5, 5, RichViewEdit1.RVData);
  for r := 0 to Table.RowCount - 1 do
    for c := 0 to Table.ColCount - 1 do
      if Table.Cells[r, c] <> nil then
      begin
        Table.Cells[r, c].Clear;
        Table.Cells[r, c].AddNL('', 0, ParaNo);
      end;
  RichViewEdit1.InsertItem('', Table);
end;
wolf1860
Posts: 108
Joined: Sat Nov 21, 2015 2:04 am

Re: How to set the alignment of TRVTableItemInfo in cell

Post by wolf1860 »

The code does not work below. What have I missed?
table.Cells[0,0].Clear;
table.Cells[0,0].AddNL('',0,2);
richView1.AddItem('mytest1', table);
tb:=TRVTableItemInfo.CreateEx(2,2,table.Cells[0,0]);
tb.BestWidth:=60;
tb.BorderColor:=clBlack;
tb.BorderWidth:=1;
table.Cells[0,0].AddItem('mytest2',tb);
RichView1.Format;
Sergey Tkachenko
Site Admin
Posts: 17236
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Re: How to set the alignment of TRVTableItemInfo in cell

Post by Sergey Tkachenko »

What does not work exactly?
wolf1860
Posts: 108
Joined: Sat Nov 21, 2015 2:04 am

Re: How to set the alignment of TRVTableItemInfo in cell

Post by wolf1860 »

I want tb align the cell's right side
Sergey Tkachenko
Site Admin
Posts: 17236
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Re: How to set the alignment of TRVTableItemInfo in cell

Post by Sergey Tkachenko »

You call AddNL with ParaNo = 2.
I do not know the value of RichView1.Style.ParaStyles[2].Alignment. If it is rvaRight, tb must be right-alignment.

To make sure that you use right alignment, use the functions from my code sample.
Instead of

Code: Select all

table.Cells[0,0].AddNL('',0,2);
call

Code: Select all

table.Cells[0,0].AddNL('',0,GetParaStyleWithAlignment(rvaRight, RichView1.Style));
wolf1860
Posts: 108
Joined: Sat Nov 21, 2015 2:04 am

Re: How to set the alignment of TRVTableItemInfo in cell

Post by wolf1860 »

It does not wort yet!

Code: Select all

table := TRVTableItemInfo.CreateEx(3, 2, richView1.RVData);
  with table do
  begin
    BorderWidth := 1;
    CellBorderWidth := 1;
  end;

  table.Cells[0, 0].BestWidth := -80;
  table.Cells[0, 1].BestWidth := -20;

  table.Cells[0, 0].BestHeight := 38;
  table.Cells[0, 0].VAlign := TRVCellVAlign.rvcMiddle;
  table.Cells[0, 1].VAlign := TRVCellVAlign.rvcMiddle;
  table.Cells[1, 0].BestHeight := 38;
  table.Cells[2, 0].BestHeight := 38;

  table.Cells[0,0].Clear;
  table.Cells[0,0].AddNL('',0,GetParaStyleWithAlignment(rvaRight,richView1.Style));
  richView1.AddItem('mytest1', table);
  tb:=TRVTableItemInfo.CreateEx(2,2,table.Cells[0,0]);
  tb.BestWidth:=60;
  tb.BorderColor:=clBlack;
  tb.BorderWidth:=1;
  table.Cells[0,0].AddItem('mytest2',tb);
  richView1.Format;
Sergey Tkachenko
Site Admin
Posts: 17236
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Re: How to set the alignment of TRVTableItemInfo in cell

Post by Sergey Tkachenko »

Before calling

Code: Select all

 table.Cells[0,0].AddItem('mytest2',tb);
call

Code: Select all

 tb.ParaNo := GetParaStyleWithAlignment(rvaRight,richView1.Style);
Post Reply