Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
630
Wingrid DrawToBitMap: Show all rows?
posted

Hello,

We have a process where we use the DrawToBitmap functionality of the Wingrid to capture an image of a grid that we then insert into a SQL Server table that is displayed as part of a Crystal Report. For the most, part this works great, but now we have some grids that have more rows than what can be displayed on the screen without scrolling.

For those situations, what we would like to know is if there is a way to use the DrawtoBitmap functionality (or something else) that will allow us to programmatically display all the rows in a grid. So, in a nutshell, if a grid has a total of 50 rows, but only enough space on the form to show 20 without scrolling, is there a way to when we are creating the image of the grid to have it show all 50 rows as opposed to the 20 that are visible on the form when creating the image?

Thanks!

Jim

Parents
  • 18204
    Offline posted

    Hello Jim,

    Thank you for posting in our forums!

    If you set the height of the grid before calling DrawToBitmap, the Bitmap will draw with the new height.  You can then set the height back right after.  You can see this in a code snippet below:

    const int BUFFER = 30;
    // Store the normal display height of the grid.
    int displayHeight = this.ultraGrid1.Height;
    // Calculate height needed for all of the rows + headers/caption/etc...
    int imageHeight = this.ultraGrid1.Rows.Count * this.ultraGrid1.Rows[0].Height + BUFFER;
    // Set the new height of the grid.
    this.ultraGrid1.Height = imageHeight;

    // Save our image.
    Bitmap bmp = new Bitmap(this.ultraGrid1.Width, imageHeight);
    this.ultraGrid1.DrawToBitmap(bmp, this.ultraGrid1.DisplayRectangle);
    bmp.Save(dialog.FileName, ImageFormat.Jpeg);

    // Set the height back to it's normal display height.
    this.ultraGrid1.Height = displayHeight;

    I have also attached a simple sample that demonstrates this.

    If you have any further questions or concerns with this, please let me know.

    WinGrid_FullSizeBitmap.zip
Reply Children
No Data