Control the width of table columns programmatically

General TRichView support forum. Please post your questions here
Post Reply
Vitalii
Posts: 69
Joined: Sat Oct 20, 2018 2:55 pm

Control the width of table columns programmatically

Post by Vitalii »

Hi, I have a specific question about tables.

The editor has a TRVTableItemInfo table that contains TRVLabelItemInfo.

According to the program logic, I programmatically change TRVLabelItemInfo.Text twice. The first time, the width of the table columns automatically adapts to the wide text, which is normal. But when I change the text to a shorter one the second time, the width of the table columns remains large (automatic adjustment does not work). If I then edit something in the table with the cursor, the columns return to the correct sizes. How can I restore the width of the columns programmatically after the second change to TRVLabelItemInfo.Text?

All operations take place within TSRichViewEdit.CanUpdate := False .. True.
Vitalii
Posts: 69
Joined: Sat Oct 20, 2018 2:55 pm

Re: Control the width of table columns programmatically

Post by Vitalii »

The sequence of actions is as follows:

1. The table contains content (text) that changes programmatically.
2. The content increases > the table columns expand.
3. The content decreases > the table columns remain wide.
4. Task: adjust the width of the columns to the current size of the content

I wanted to save the table settings before the changes and restore them after the changes. But I couldn't find a method or property that is responsible for the exact width of the table columns. But it would be enough to simply change something “in the background” in the table to update the width of the columns, as happens when I edit the table manually.
Sergey Tkachenko
Site Admin
Posts: 18011
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Re: Control the width of table columns programmatically

Post by Sergey Tkachenko »

In order to help, I need to know how you change content size in code.
Please send me a code fragment or (better) a simple project reproducing the problem.
Vitalii
Posts: 69
Joined: Sat Oct 20, 2018 2:55 pm

Re: Control the width of table columns programmatically

Post by Vitalii »

The content in the table changes via TRVLabelItemInfo.Text:

Code: Select all

SRichViewEdit.CanUpdate := False;
try
  ALabel.Text := '<some large text>'; // <-- here the table extends (expected behavior)
  { other operations... }
  ALabel.Text := 'A'; // <-- here, the table width should return to normal (but it doesn't)
finally
  SRichViewEdit.RVHeader.Reformat;
  SRichViewEdit.RichViewEdit.Reformat;
  SRichViewEdit.RVFooter.Reformat;
  SRichViewEdit.CanUpdate := True;
end;
Sergey Tkachenko
Site Admin
Posts: 18011
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Re: Control the width of table columns programmatically

Post by Sergey Tkachenko »

I confirm the problem.
It will be fixed in the next update.
As a workaround, call ALabel.UpdateMe immediately after changing ALabel.Text.
Vitalii
Posts: 69
Joined: Sat Oct 20, 2018 2:55 pm

Re: Control the width of table columns programmatically

Post by Vitalii »

Thanks, it works.
Post Reply