Search This Blog

Friday, July 12, 2013

Export RadGridView to Bitmap full Size

Telerik > Windows Forms > Export RadGridView to Bitmap

Sometimes is useful to export Telerik Rad Grid to image to its full size without regard of scroll bars.




Example:

Private Function GetImage(grd As Telerik.WinControls.UI.RadGridView)
        grd.Visible = False
        grd.Dock = DockStyle.None
        Dim w = 0
        For Each col In grd.Columns
            w = w + col.Width
        Next
        grd.Width = w
        If grd.Rows.Count > 0 Then
            grd.Height = (grd.Rows.Count * grd.Rows(0).Height)
        Else
            grd.Height = 150
        End If

        Dim bitmap As New Bitmap(grd.Bounds.Width, grd.Bounds.Height)
        grd.DrawToBitmap(bitmap, grd.Bounds)
        grd.Dock = DockStyle.Fill
        grd.Visible = True

        Return bitmap
End Function