09-22-2011 08:53 AM
Hello,
I would like to print all data in a control Table, the visible lines and the others which are not visible, to part if we move the scrollbar of this control. When I print the panel or the control, the printing contains the visible data on the screen at this moment, but not the data of the table which are not in the screen.
The code that I use is this one:
SetPrintAttribute( ATTR_PRINT_AREA_HEIGHT, VAL_USE_ENTIRE_PAPER );
SetPrintAttribute( ATTR_PRINT_AREA_WIDTH, VAL_INTEGRAL_SCALE );
SetPrintAttribute( ATTR_ORIENTATION, VAL_LANDSCAPE );
SetPrintAttribute( ATTR_COLOR_MODE, VAL_BW );
SetPrintAttribute( ATTR_XOFFSET, VAL_CENTER_ON_PAPER );
SetPrintAttribute( ATTR_YOFFSET, VAL_CENTER_ON_PAPER );
SetPrintAttribute( ATTR_XRESOLUTION, -1);
SetPrintAttribute( ATTR_YRESOLUTION, -1 );
SetPrintAttribute( ATTR_SHOW_PAGE_NUMBERS, 1 );
//PrintPanel( hand_AuditTrail, "", 1, VAL_VISIBLE_AREA, 1);
//PrintPanel( hand_AuditTrail, "", 1, VAL_FULL_PANEL, 1);
GetActiveTabPage (hand_AuditTrail, AUDITTRAIL_TAB_AuditTrail, &index_tabpage);
PrintCtrl (hand_AuditTrail, AUDITTRAIL_TAB_AuditTrail, "", 1, 1);
Anybody can help me please?
Thanks Bybye
Karine
09-22-2011 09:37 AM - edited 09-22-2011 09:38 AM
You could show all table rows when printing the control next restoring the table to its original dimension aftewards:
GetCtrlAttribute (..., ..., ATTR_NUM_VISIBLE_ROWS, &visible); GetNumTableRows (..., ..., &rows); SetCtrlAttribute (..., ..., ATTR_NUM_VISIBLE_ROWS, rows); PrintCtrl (...); SetCtrlAttribute (..., ..., ATTR_NUM_VISIBLE_ROWS, visible);
I don't know what happens if the resulting table does not fit in one page.
09-22-2011 10:37 AM
Thanks for your answer, your solution is almost perfect! The printing contains more lines than previously, and more than the displays in front of me, but it contains only one page while there are still lines in the table.
I don't manage to print several pages, and I saw your comment "I don't know what happens if the resulting table does not fit in one page."
So I think you will not help me more.
If you have or you find the solution of the second problem, don't hesitate to help me please and contact me.
Thank you again for your help.
Karine
09-22-2011 10:51 AM - edited 09-22-2011 10:52 AM
If the table spans over multiple pages I suppose you can see how many table rows can fit in one page and iterate on the table this way:
SetCtrlAttribute (..., ..., ATTR_NUM_VISIBLE_ROWS, LinesPerPage);
page = 0;
while (1) {
SetCtrlAttribute (..., ..., ATTR_FIRST_VISIBLE_ROW, LinesPerPage * page + 1);
PrintCtrl (...);
page++;
// If table ended, exit the loop
}
On the last page you may want to reduce the visible lines to the exact number of rows left to print.
09-23-2011 06:41 AM
Thanks you for this solution, it's good. However a last problem appears to the printing, in spite of the using of the function SetCtrlAttribute on attribute ATTR_FIRST_VISIBLE_ROW which works, on the printing of second page some lines of the first one appear. But in the display the attribute was applied. As if the function PrintPanel would have been sent while the attribute would not have been completely applied...
Do you have an idea please?
Thanks again !
Karine
09-23-2011 08:07 AM
Is the second the last page printed? If so, you may be running into a problem in visible lines in the table.
Let me make an example: suppose your table contains 100 rows and on one page you can print only 60 of them.
The first page is printed correctly with 60 rows.
Next you set ATTR_FIRST_VISIBLE_ROW to 61 but your table has to show 60 lines, so it may happen that it actually displays lines from 41 to 100, that are then sent to the printer.
I have not tested it, but if this is true you need to limit the number of visible lines on the table to 40 before updating the first visible row, so that the control holds the correct set of data before printing.
As far as I can understand, PrintCtrl takes a snapshot of control aspect and sends it to the printer, it makes no difference for it that the control is a table, a graph, a picture or a single numeric: as it is on screen it is displayed; it is difficult for me to accept that you see line 61 on top of the table on screen and line 41 on paper!
09-26-2011 01:45 PM
Thanks, I had basically the same thing.
09-27-2011 03:02 AM
Sorry I didn't answer yesterday, concerning our topic, the page which contains some lines identical to the previous one is not the last. Another page is then printed.
I made a test by limiting the number of pages to 2.
So as attachment, you find exactly what's happens.
A file ("Word") with the code, a file ("Word") with the print screen of windows which appears, and another file ("PDF") with what is printed.
It's very surprising.
Karine.
09-30-2011 09:02 AM
Hello!
Just another message to say there is a real problem with the function PrintPanel, this function doesn't print exactly the window which is in front of me.
Thus I can't print all the last lines of my table.
Bye.
Karine
10-03-2011 07:17 AM
Hi Karine,
when looking at the problems you are finding, there a small detail that may help you in understanding how tables are managed.
If you place a table on a panel and look at the number of rows that it can hold, you may find a value that is different from the lines that can actually fit into it: apparently the table control calculates the number of rows based on a fixed row height, but the default size mode for rows is to dimension them automatically based on font height/image height. This causes some confusion to me: on my system, using NI Dialogue, 13 pt, Native font, a given table gives a calculated number of rows of 15, but I can actually fill it with 17 visible rows if I leave the automatic row sizing. If I set every row to manually size to 25 pizels there actually fit exactly 15 rows in the table.
Another element of confusion is that if you set the table height to fit <n> rows + 1 pixels, ATTR_VISIBLE_ROWS returns <n + 1> ![]()
As a ultimate workaround for your problem, I suggest you to:
1. Explicitly size table rows by adding those lines to your code after inserting rows:
SetTableRowAttribute (tabHandle, TABPANEL_TABLE, -1, ATTR_SIZE_MODE, VAL_USE_EXPLICIT_SIZE); SetTableRowAttribute (tabHandle, TABPANEL_TABLE, -1, ATTR_ROW_HEIGHT, 25);
2. Force an exact number of rows displayed by the following command:
SetNumTableRows (panelHandle, PANEL_TABLE, visibleRows);
Using those two little tricks and appropriately dimensioning the variables you should be able to print exacly all rows in your table.