Hi,
I try to preview a UltraWinGrid that contains 2 columns and 42 rows. One colum has type string and the other one bitmap. The second column is filled with images with size 21900x20 for each row.
I'm using the following code:
private
fullBmp;
;
e)
{
.OK)
fileName = openFileDialog1.FileName;
fullBmp = (
.FromFile(fileName);
();
table.Columns.Add(
)));
i = 0; i < 42; i++)
row = table.NewRow();
(i == 0)
row[
}
else
+ i.ToString();
.Format16bppRgb565);
] = b;
table.Rows.Add(row);
mPrintGrid =
mPrintGrid.InitializeLayout +=
(mPrintGrid_InitializeLayout);
mPrintGrid.InitializeRow +=
(mPrintGrid_InitializeRow);
//mPrintGrid.DisplayLayout.Override.DefaultRowHeight = mRowHeight;
mPrintGrid.DisplayLayout.Override.CellSpacing = 0;
mPrintGrid.DisplayLayout.Override.CellPadding = 0;
mPrintGrid.Parent =
mPrintGrid.DataSource = table;
mPrintGrid.Dock =
.Fill;
gridPanel.Controls.Add(mPrintGrid);
mPrintGrid.PrintPreview();
//mPrintGrid.Print();
e.Layout.Bands[0].ColHeadersVisible =
e.Layout.Bands[0].Override.RowSizing =
.Free;
e.Layout.Bands[0].Override.RowSpacingAfter = 0;
e.Layout.Bands[0].Override.RowSpacingBefore = 0;
e.Layout.Bands[0].Columns[
].Width = 21900;
//e.Layout.Bands[0].Columns["Image"].MergedCellStyle = MergedCellStyle.Always;
//e.Layout.Bands[0].Columns["Image"].MergedCellEvaluationType = MergedCellEvaluationType.MergeSameValue;
////e.Layout.Bands[0].Columns["Image"].MergedCellEvaluator = new ImageMergedCellEvaluator();
(e.Row.Index == 0)
e.Row.Height = 40;
e.Row.Height = 20;
The exception occurs while the preview pages are generating:
************** Exception Text **************System.Runtime.InteropServices.ExternalException: A generic error occurred in GDI+. at System.Drawing.Graphics.CheckErrorStatus(Int32 status) at System.Drawing.Graphics.DrawImage(Image image, Rectangle destRect, Int32 srcX, Int32 srcY, Int32 srcWidth, Int32 srcHeight, GraphicsUnit srcUnit, ImageAttributes imageAttrs, DrawImageAbort callback, IntPtr callbackData) at System.Drawing.Graphics.DrawImage(Image image, Rectangle destRect, Int32 srcX, Int32 srcY, Int32 srcWidth, Int32 srcHeight, GraphicsUnit srcUnit, ImageAttributes imageAttr, DrawImageAbort callback) at System.Drawing.Graphics.DrawImage(Image image, Rectangle destRect, Int32 srcX, Int32 srcY, Int32 srcWidth, Int32 srcHeight, GraphicsUnit srcUnit, ImageAttributes imageAttr) at Infragistics.Win.DrawUtility.DrawImage(Graphics g, Image image, Rectangle destRect, Rectangle srcRect, Int16 alphaLevel, ImageAttributes imgAttributes, Boolean tile, ColorRenderMode colorRenderMode, ImageBackgroundStretchMargins margins) at Infragistics.Win.DrawUtility.DrawImage(Graphics g, Image image, Int16 alphaLevel, Rectangle destRect, Rectangle srcRect, Rectangle invalidRect, ImageAttributes imgAttributes, Boolean tile, ColorRenderMode colorRenderMode) at Infragistics.Win.DrawUtility.DrawImage(Graphics g, Image image, AppearanceData& appearanceData, AlphaBlendMode alphaMode, Boolean scaled, Rectangle renderRect, Rectangle invalidRect, ImageAttributes imgAttributes, Boolean maintainAspectRatio, Boolean drawBorderShadow, Color shadowColor, Byte startAlpha, Byte endAlpha, Byte shadowDepth, ColorRenderMode colorRenderMode) at Infragistics.Win.UIElementDrawParams.DrawImage(Image image, Rectangle rect, Boolean scaled, ImageAttributes imgAttributes, Boolean maintainAspectRatio, Boolean drawBorderShadow, Color shadowColor, Byte startAlpha, Byte endAlpha, Byte shadowDepth) at Infragistics.Win.ImageUIElementBase.DrawImage(UIElementDrawParams& drawParams) at Infragistics.Win.UIElement.DrawElement(UIElementDrawParams& defaultDrawParams) at Infragistics.Win.UIElement.DrawChildElements(UIElementDrawParams& drawParams) at Infragistics.Win.UIElement.DrawElement(UIElementDrawParams& defaultDrawParams) at Infragistics.Win.UIElement.DrawChildElements(UIElementDrawParams& drawParams) at Infragistics.Win.UIElement.DrawElement(UIElementDrawParams& defaultDrawParams) at Infragistics.Win.UIElement.DrawChildElements(UIElementDrawParams& drawParams) at Infragistics.Win.UIElement.DrawElement(UIElementDrawParams& defaultDrawParams) at Infragistics.Win.UIElement.DrawChildElements(UIElementDrawParams& drawParams) at Infragistics.Win.UIElement.DrawElement(UIElementDrawParams& defaultDrawParams) at Infragistics.Win.UIElement.DrawChildElements(UIElementDrawParams& drawParams) at Infragistics.Win.UIElement.DrawElement(UIElementDrawParams& defaultDrawParams) at Infragistics.Win.UIElement.DrawChildElements(UIElementDrawParams& drawParams) at Infragistics.Win.UIElement.DrawElement(UIElementDrawParams& defaultDrawParams) at Infragistics.Win.UIElement.DrawChildElements(UIElementDrawParams& drawParams) at Infragistics.Win.UIElement.DrawElement(UIElementDrawParams& defaultDrawParams) at Infragistics.Win.UIElement.DrawHelper(Graphics graphics, Rectangle invalidRectangle, Boolean doubleBuffer, AlphaBlendMode alphaBlendMode, Boolean clipText, Boolean forceDrawAsFocused) at Infragistics.Win.UIElement.Print(Graphics graphics, Boolean clipText) at Infragistics.Win.UltraWinGrid.PrintManager.PrintPage(Object sender, PrintPageEventArgs ev) at System.Drawing.Printing.PrintDocument.OnPrintPage(PrintPageEventArgs e) at System.Drawing.Printing.PrintDocument._OnPrintPage(PrintPageEventArgs e) at System.Drawing.Printing.PrintController.PrintLoop(PrintDocument document) at System.Drawing.Printing.PrintController.Print(PrintDocument document) at System.Drawing.Printing.PrintDocument.Print() at System.Windows.Forms.PrintPreviewControl.ComputePreview() at System.Windows.Forms.PrintPreviewControl.CalculatePageInfo() at System.Windows.Forms.Control.InvokeMarshaledCallbackDo(ThreadMethodEntry tme) at System.Windows.Forms.Control.InvokeMarshaledCallbackHelper(Object obj) at System.Threading.ExecutionContext.runTryCode(Object userData) at System.Runtime.CompilerServices.RuntimeHelpers.ExecuteCodeWithGuaranteedCleanup(TryCode code, CleanupCode backoutCode, Object userData) at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state) at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state) at System.Windows.Forms.Control.InvokeMarshaledCallback(ThreadMethodEntry tme) at System.Windows.Forms.Control.InvokeMarshaledCallbacks()
The error message you are getting here seems to indicate that the GDI+ drawing code is blowing up when trying to draw such a large image. I doubt this has anything to do with the grid, it's just that your image is too large for Windows to deal with.
Why would you want to use an image that is 20 times the width of the average screen?
The image is the result of the drawn planning control. The width depends the zoom applyed the user. There is no way to get that planning but as a drawing output.
Now, I have to print this image along with some additional data that is already bound in a UltraGrid.
Hi Mike,
I found a workaround for drawing issue. It seems the DrawToBitmap method is drawing the entire control if the control is NOT visible! The only challenge is to get the required size to draw the entire grid. But also this can be done if you iterate thru the rows/columns collections and increment the height/width values plus some borders.
Thank you for your feedback.
There's no easy way to get an image of the entire contents of the grid. That's what the grid's Printing code does - it draws the grid onto a graphics object provided by the PrintDocument. The code is quite complex and basically involves creating a UIElement that contains the same rows as the grid and then drawing it, then scrolling it to the next page full of rows, drawing it, etc.
I will try to sent small images to the printer, but I need the grid image somehow....
I got your point. On the other hand, i'm wondering how to save the entire UltraGrid content to an Image? Using the Control.DrawToBitmap will draw only the visible part of the grid.
Thank you for your support.
razvann
As I said, I don't think this has anything to do with the grid. The image is incredibly large and it looks like Windows or DotNet drawing code is blowing up when the grid attempts to draw it on the print surface, which is really not surprising.
Even if this worked, it would take a forest-worth of paper to print it out on. :)
You probably need to reduce the size of the image.