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.