Hello,
I have a UltraWinGrid, and I want to print it with a UltraGridPrintDocument.
But I want to use Page break for each Grid's Groups.
Is it possible to use Page break with printing a UltraWinGrid into a UltraGridPrintDocument ?
No, I don't beleive this is currently possible. You might be able to do multiple print jobs by hiding all the rows except for the ones in a particular group, print the grid, then hide everything except for the second group, print that, etc.
Hello, Mike.
I need the same thing: page breaks. Did you implemented this feature?
I don't know if you did so I tried to implement what you have suggested in the previous post, but to no avail.
I was thinking of a slightly different approach.
- print the current contents of the UltraGrid in an UltraPrintDocument;
- refill the UltraGrid with something else
- print the UltraGrid, with the new info, in the same UltraPrint Document
...and so on, I am sure you got the picture.
The problem is that I don't know what to use: UltraPrintDocument or UltraGridPrintDocument?
And, the most important, when should I refill the grid (its data source, in fact) and reinitiate the printing, of course, in the same document used before?
I tried to handle the PagePrinted and EndPrint events of the UltragridPrintedDocument and, next, I handled the same events for the UltraPrintDocument. In every case I got all sort of wrong behaviors when I was trying to print the UltraGrid for the second time (containing the new data): exceptions or countless documents printed somewhere but not into the document I wanted to print ...
Do I need to handle the printing related events of the UltraGrid (InitializePrint, BeforePrint)?
This is drriving me nuts, so I would really appreaciate any pointers or hints.
Thank you in advance.
Daniel
Hi Daniel,
Well, I cannot say for sure that this won't work. If you have the time, you could try it. Setting HasMorePages may work. But I suspect you will run into some weird behavior or possibly even an exception if you change the DataSource on the grid while you it is in the middle of printing. The grid code simply does not expect this to happen and so it's probably not going to handle it very well.
Thank you for your quick reply, Mike.
You roughly got the idea. I was thinking of setting HasMorePagesof the UltraPrintDocument to true when the grid finishes printing the current batch of rows, refilling the grid and somehow reinitiating the printing process for the grid, with the new data, but in the same document, as a new page.
Why did I take this approach? Because I have already done this, but with another control. That control has two methods, PrintInit and PrintEnd, which initialize the printing process and reset everything for the control after the printing is finished. The actual printing is performed by its PrintPage method. This method receives a Rectangle in which it will perform the printing.
So, basically, all I have to do is to handle the PrintPage event of the UltraPrintDocument, in which I tell the control to print into the rectangle I get from the PageBound object supplied in the event. Of course, I also tell it what to print, which in your case would be the starting row and ending rows and the starting column and ending column. When I decide that I printed what I need from one instance of the control, I tell UltraPrintDocument that there are some more pages to print (e:HasMorePages = true) and initiate the printing process for another instance of that control.
In this way I managed to print the contents of two instances of that control, one after another, in the same document. I have even printed a part of one control in the upper half of the page and a part from the second instance into the lower part of the page.
The difference is that the printing process of that control is very customizable, unlike the printing of the UltraGrid, which is a black box, from what I have seen. Please correct me if I am wrong.
I have noticed that many people ask for this "Page break" feature. I would also ask for a more customizable (controllable) printing process for the UltraGrid.
You could take this as a hint or as a suggestion, it is up to you.
Again, thank you for your help.
DanielB
So, the idea is that you would populate a grid with the data from only the first group, print it, then populate the grid with the data from the second group, print that, etc.?
That seems like feasible approach. But you don't need to handle any events of the grid to do that. You should just write the code in a linear way. It's all synchronous. You bind the grid, print it, bind it to a new DataSource, print it, etc.
The biggest down side to this approach that I can see is that each print operation is going to create it's own print job. So it will not be possible to show a print preview with the whole thing.
EDIT: Oh... are you thinking that you can modify the grid contents as the print operation is occurring so that the grid thinks there's nothing more on the page? I don't think that would work. For one thing, I'm pretty sure that the grid figures out the first row that will be on each page up-front, before it actually starts printing. So modifying the contents of the grid during the print operation would not be a good idea and would most likely cause an exception.
I really don't see any feasible way to do that.