Page 1 of 1

How to set the alignment of TRVTableItemInfo in cell

Posted: Tue Aug 21, 2018 2:29 pm
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!

Re: How to set the alignment of TRVTableItemInfo in cell

Posted: Tue Aug 21, 2018 2:53 pm
by Sergey Tkachenko
In TRichView, cells do not have horizontal alignment properties.
Align all paragraphs in the cell to the right.

Re: How to set the alignment of TRVTableItemInfo in cell

Posted: Tue Aug 21, 2018 3:08 pm
by wolf1860
How? The cell is empty before I insert a TRVTableItemInfo.

Re: How to set the alignment of TRVTableItemInfo in cell

Posted: Tue Aug 21, 2018 3:25 pm
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;

Re: How to set the alignment of TRVTableItemInfo in cell

Posted: Tue Aug 21, 2018 4:02 pm
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;

Re: How to set the alignment of TRVTableItemInfo in cell

Posted: Tue Aug 21, 2018 6:18 pm
by Sergey Tkachenko
What does not work exactly?

Re: How to set the alignment of TRVTableItemInfo in cell

Posted: Tue Aug 21, 2018 11:26 pm
by wolf1860
I want tb align the cell's right side

Re: How to set the alignment of TRVTableItemInfo in cell

Posted: Wed Aug 22, 2018 7:46 am
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));

Re: How to set the alignment of TRVTableItemInfo in cell

Posted: Wed Aug 22, 2018 2:32 pm
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;

Re: How to set the alignment of TRVTableItemInfo in cell

Posted: Fri Aug 24, 2018 10:01 pm
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);