Page 1 of 1
Code To Widen Last Column Doesn't Work
Posted: Mon Sep 29, 2008 9:37 am
by fchintc
Hi,
I have the following table:-
I want the last column of the table to be widened up to the right margin of the page so that it looks like the following:-
However, using the following code, I cannot get the last column to widen:-
Code: Select all
table.BestWidth:=-100;
for nX := 0 to table.RowCount-1 do begin
if table.Cells[nX, table.ColCount-1]<>nil then begin
table.Cells[nX, table.ColCount-1].BestWidth := 0;
end;
end;
After the above code is run, I get the following printout:-
If I manually resize the table like the following, I will get the printout I want:-
How can I get the code to work?
Thanks.
Frederick
Posted: Mon Sep 29, 2008 1:56 pm
by Sergey Tkachenko
The code I gave before reset width of cells in the last column. But your table is more complex, it has cells in previous columns spanning over the last column.
Try this code instead:
Code: Select all
var r,mr,mc: Integer;
table.BestWidth:=-100;
for r := 0 to table.RowCount-1 do begin
table.Rows.GetMainCell(r, table.ColCount-1, mr, mc);
table.Cells[mr, mc].BestWidth := 0;
end;
Posted: Tue Sep 30, 2008 1:28 am
by fchintc
Thanks for the code.
The result of the new code is as follows with the right columns of the first two rows still not stretching to the right margin of the page:-
Any other suggestions?
Thanks.
Frederick
Posted: Tue Sep 30, 2008 4:46 am
by Sergey Tkachenko
I can see several grid lines to the right side of the table, in the first two rows.
It looks like there are one or more empty columns at the end of the table. Size of this empty column is increased, while other columns remain of the same size.
Posted: Tue Sep 30, 2008 2:26 pm
by fchintc
Sergey Tkachenko wrote:I can see several grid lines to the right side of the table, in the first two rows.
It looks like there are one or more empty columns at the end of the table. Size of this empty column is increased, while other columns remains of the same size.
In that case, the solution may be to determine if the last column for the row is blank. If it is, set the bestwidth for the column before it to 0. How to I determine if a column is blank?
Frederick
Posted: Tue Sep 30, 2008 3:22 pm
by Sergey Tkachenko
Please send me RVF file with this table.
Posted: Wed Oct 01, 2008 1:15 am
by fchintc
I have sent you the table that is a RTF in a DBISAM BLOB field. Hope that the format is OK. I couldn't get it to export to a RTF file.
Frederick
Posted: Thu Oct 02, 2008 5:56 pm
by Sergey Tkachenko
Ok, these unnecessary columns at the end of the table have small widths, 2 pixels or less.
So, before changing table width, we need to delete these columns.
Code: Select all
var
r,c,w,mr,mc: Integer;
for c := table.ColCount-1 downto 0 do begin
w := 0;
for r := 0 to table.RowCount-1 do
if (table.Cells[r,c]<>nil) and (table.Cells[r,c].Width>w) then begin
w := table.Cells[r,c].Width;
if w>2 then
break;
end;
if (w>2) or (c=0) then begin
if (c<table.ColCount-1) then
table.DeleteCols(c+1, table.ColCount-1-c, False);
break;
end;
end;
table.BestWidth:=-100;
for r := 0 to table.RowCount-1 do begin
table.Rows.GetMainCell(r, table.ColCount-1, mr, mc);
table.Cells[mr, mc].BestWidth := 0;
end;
Posted: Fri Oct 03, 2008 10:06 am
by fchintc
Thank you very much for the code! It works nicely.
Frederick