Data grid is not properly printing
-
Friday, October 12, 2012 5:53 AM
Hi Experts,
Thanks for your support.
I am facing a problem while try to print the data grid.
It is printing only the record am able to see. and not printing the records below the scrolling part.
I have written the code like this :
#region PrintDoc
private void btnPrintDoc_Click(object sender, RoutedEventArgs e)
{
PrintDocument doc = new PrintDocument();
doc.BeginPrint += new EventHandler<BeginPrintEventArgs>(doc_StartPrint);
doc.PrintPage += new EventHandler<PrintPageEventArgs>(doc_PrintPage);
doc.Print("Sample Print");
}
void doc_PrintPage(object sender, PrintPageEventArgs e)
{
e.PageVisual =dataGrid1;
// Specify whether to call again for another page
e.HasMorePages = false;
}
void doc_StartPrint(object sender, BeginPrintEventArgs e)
{
// NOOP
}
#endregionCan you please suggests me how I will print all rows of my data grid?
All Replies
-
Friday, October 12, 2012 9:24 AM
Please if anyone know this just reply.
Its my urgent requirement.
-
Friday, October 12, 2012 10:03 AM
http://www.infragistics.com/community/forums/p/72968/371019.aspx
http://stackoverflow.com/questions/3933565/silverlight-4-printing-api
http://www.davidpoll.com/2010/04/16/making-printing-easier-in-silverlight-4/ -
Monday, October 15, 2012 1:21 AM
Hi Carom,
Thanks for the link.But this is not sufficient for my requirement.
Can you tell me how i will solve this?
-
Monday, October 15, 2012 4:47 AM
Hi Experts I am trying to print the Datagrid in the following approach
PrintDocument doc = new PrintDocument();
int itemsIndex = 0;
doc.PrintPage += (s, pe) =>
{StackPanel itemsHost = new StackPanel();
while (itemsIndex < loadItem.Count())
{
ItemsControl itemsContainer = new ItemsControl();
itemsContainer.DataContext = loadItem[itemsIndex];
itemsHost.Children.Add(itemsContainer);
itemsHost.Measure(new Size(pe.PrintableArea.Width, double.PositiveInfinity));
if (itemsHost.DesiredSize.Height > pe.PrintableArea.Height && itemsHost.Children.Count > 1)
{
itemsHost.Children.Remove(itemsContainer);
pe.HasMorePages = true;
// return;
break;}
itemsIndex += 1;
}
pe.PageVisual = itemsHost;};
doc.Print("dataGrid1");**********************************************
Still I am getting error on last line that "Dialogs must be user-initiated."
Can anybody simplify this?
-
Thursday, October 18, 2012 10:50 AMModerator
Hi, I suggest to create a new DataGrid instance code behind which has the same data source with the DataGrid you want print, and set its width and height bigger enough so that it can fullfill all records without draging scrollbar and then you print the new DataGrid.
Hope this will help you.
Best Regards,
-
Thursday, October 18, 2012 11:45 AM
Hi man.
It is printing only the record am able to see. and not printing the records below the scrolling part.
1) Just turn OFF the DataGrid UI Virtualization
Dialogs must be user-initiated
1) Create a new DataGrid in the background, fill it with the same data, and print that instead.
You must read this too:
-
Friday, October 19, 2012 12:17 AM
Thank you iTateSLC for your answer,
I have implemented the way you said,now its working fine.
But when I try to take a printout ,the page is not properly fit to the datagrid .(As I have more number of columns)
and how to set if I have more data then it should print in the next page.
Please suggests me.

