We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. (Last updated on: November 16, 2018).
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

How to display header only on first page when previewing

Thread ID:

Created:

Updated:

Platform:

Replies:

127473 Nov 17,2016 01:30 PM UTC Nov 30,2016 04:24 AM UTC WinForms 7
loading
Tags: GridGroupingControl
Hussain
Asked On November 17, 2016 01:30 PM UTC

Hi..
I am using GroupingGridPrintDocumentAdv to print a gridgroupingcontrol with a header and footer, how can i display the header only on first page.
The only property related to header is GroupingGridPrintDocumentAdv.HeaderHeight..any help??

Amal Raj Umapathy Selvam [Syncfusion]
Replied On November 18, 2016 07:18 AM UTC

Hi Hussain, 

Thanks for using Syncfusion products. 

In order to avoid displaying the Header only in the first page, then DrawGridPrintHeader event can be used. Please make use of the below code, 
 
Code Example 
//Event Subscription. 
printDocument.DrawGridPrintHeader += new GridPrintDocumentAdv.DrawGridHeaderFooterEventHandler(printDocument_DrawGridPrintHeader); 
 
void printDocument_DrawGridPrintHeader(object sender, GridPrintHeaderFooterTemplateArgs e) 
    if (e.PageNumber > 1) 
    { 
        //To avoid Headers in pages other than first page. 
        e.Cancel = true
    } 
 
Sample Link 
 
Regards, 
Amal Raj U. 


Hussain
Replied On November 20, 2016 09:17 AM UTC

Hi Amal,

Thank you for answering.

i want to display header only on then first page. I managed to display it only on first page either by making GroupingGridPrintDocumentAdv.HeaderHeight = 0, or by removing the handler of GroupingGridPrintDocumentAdv.DrawGridPrintHeader, but the header place is still reserved as shown in the file i attached.what i want is to make the grid in the second page fills the hole page excepting the footer place.

Note: i am using vb.net



Attachment: header_1eb9bc4b.rar

Amal Raj Umapathy Selvam [Syncfusion]
Replied On November 21, 2016 12:22 PM UTC

Hi Hussain, 

Thanks for the update. 

The header space for the pages other than first page can be removed by removing the allotted margins for the headers to the page. Please make use of the below code, 

Code Example 
void printDocument_DrawGridPrintHeader(object sender, GridPrintHeaderFooterTemplateArgs e) 
    if (e.PageNumber == 1) 
        firstPagePrinted = true
    else 
    { 
        //To avoid Headers in pages other than first page. 
        e.Cancel = true
    }            

void printDocument_PrintPage(object sender, PrintPageEventArgs e) 
    if (firstPagePrinted) 
        e.PageSettings.Margins = new Margins(0, 0, 0, 0); 
 
Sample Link 

Regards, 
Amal Raj U. 


Hussain
Replied On November 22, 2016 12:06 PM UTC

Hi Amal.

It worked for the grid to occupy the header place, but still not filling the hole page.
I also noticed (in your example too) that the grid size in the rest of pages (except the last page) is the same as the grid in the first page despite of the extra space in the rest of pages which has been created by removing header. 

Note : if you attached an example i prefer it to be written with vb.net not C#. I also attached a sample output.

Thanks in advance

Attachment: header_1ca46f6d.rar

Amal Raj Umapathy Selvam [Syncfusion]
Replied On November 23, 2016 02:15 PM UTC

Hi Hussain, 

Thanks for the update. 

By default, number of records that’s going to print in single page is calculated internally before printing the grid data. Since there is no direct support for hiding the Headers in particular page, managing the margins of page will result in some empty spaces. This cannot be removed directly. 

However the space can be avoided by printing some more records of grid by specifying the records to be printed using PrintInfo.m_awPageFirstRow collection which maintains the number of records to be printed in each page. By modifying this collection with our records, we can remove the unwanted spaces. Please make use of the below code, 
 
Code Example 
bool firstPagePrinted = true; int pageIndex = 1; int NoOfRecordsToAdd = 2; 
void printDocument_PrintPage(object sender, PrintPageEventArgs e) 
{ 
    if (firstPagePrinted) 
    { 
        e.PageSettings.Margins = new Margins(0, 0, 0, 0); 
        if (pageIndex + 1 < this.gridGroupingControl1.TableControl.PrintInfo.m_awPageFirstRow.Count) 
        { 
            int nextFirstRowValue = (int)this.gridGroupingControl1.TableControl.PrintInfo.m_awPageFirstRow[pageIndex + 1]; 
            int lastRowValue = (int)this.gridGroupingControl1.TableControl.PrintInfo.m_awPageFirstRow[this.gridGroupingControl1.TableControl.PrintInfo.m_awPageFirstRow.Count - 1]; 
            if (nextFirstRowValue + (pageIndex * NoOfRecordsToAdd) < lastRowValue) 
                this.gridGroupingControl1.TableControl.PrintInfo.m_awPageFirstRow[pageIndex + 1] = nextFirstRowValue + (pageIndex * NoOfRecordsToAdd); 
            else 
            { 
                this.gridGroupingControl1.TableControl.PrintInfo.m_awPageFirstRow[pageIndex + 1] = (int)this.gridGroupingControl1.TableControl.PrintInfo.m_awPageFirstRow[this.gridGroupingControl1.TableControl.PrintInfo.m_awPageFirstRow.Count - 1]; 
                for (int i = pageIndex + 2; i < this.gridGroupingControl1.TableControl.PrintInfo.m_awPageFirstRow.Count; i++) 
                { 
                    this.gridGroupingControl1.TableControl.PrintInfo.m_awPageFirstRow.RemoveAt(i); 
                } 
            } 
        } 
        pageIndex++; 
    } 
} 
 
Sample Link 

Note 
NoOfRecordsToAdd defines the number of records to be added in the remaining empty spaces. The above customization for changing the PrintInfo.m_awPageFirstRow may differs with your Grid’s bounds based on remaining empty spaces. You can customize the PrintInfo.m_awPageFirstRow as per your remaining empty spaces. 
 
If the number of records to be printed in the page exceeds the maximum bounds area, then that page will not printed. 
 
Regards, 
Amal Raj U. 


Hussain
Replied On November 29, 2016 12:06 PM UTC

Hi Amal.

Thanks. Almost every thing worked fine except this part,

for (int i = pageIndex + 2; i < this.gridGroupingControl1.TableControl.PrintInfo.m_awPageFirstRow.Count; i++) 
                { 
                    this.gridGroupingControl1.TableControl.PrintInfo.m_awPageFirstRow.RemoveAt(i); 
                } 

which some times generates index out of bound exception but i fixed it by replacing it with these lines,

While gridP.TableControl.PrintInfo.m_awPageFirstRow.Count > pageIndex + 2
                        gridP.TableControl.PrintInfo.m_awPageFirstRow.RemoveAt(gridP.TableControl.PrintInfo.m_awPageFirstRow.Count - 1)
                    End While

Amal Raj Umapathy Selvam [Syncfusion]
Replied On November 30, 2016 04:24 AM UTC

Hi Hussain, 

Thanks for the update. 

We are glad to know that you have resolved the issue with the provided solution. Please let us know, if you have any concerns. 

Regards, 
Amal Raj U. 


CONFIRMATION

This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

Please sign in to access our forum

or the page will be automatically redirected to sign-in page in 10 seconds.

Warning Icon You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.Close Icon

;