This is a migrated thread and some comments may be shown as answers.

Export to PDF

1 Answer 90 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Joel Jordan
Top achievements
Rank 1
Joel Jordan asked on 26 May 2011, 02:41 PM
I am using the latest version of the winforms controls (2011.1.11.419).  When exporting to PDF, my code is not raising the HTMLCellFormatting event.  Here is the pdf export code.

Dim oPdfExporter As ExportToPDF = New ExportToPDF(Me._oSelectedGrid)
oPdfExporter.FileExtension = "pdf"
oPdfExporter.PageTitle = "Dealer Inventory"
oPdfExporter.Scale = 0.5F
oPdfExporter.PdfExportSettings.PageHeight = 210
oPdfExporter.PdfExportSettings.PageWidth = 297
oPdfExporter.ExportVisualSettings = False
oPdfExporter.HiddenColumnOption = HiddenOption.DoNotExport
oPdfExporter.HiddenRowOption = HiddenOption.DoNotExport
oPdfExporter.SummariesExportOption = SummariesOption.DoNotExport
oPdfExporter.FitToPageWidth = True
oPdfExporter.PdfExportSettings.FontType = Telerik.Apoc.Render.Pdf.FontType.Embed
Dim sTempPath As String = My.Computer.FileSystem.SpecialDirectories.CurrentUserApplicationData & "\Dealer_Inventory.pdf"
oPdfExporter.RunExport(sTempPath)
oPdfExporter = Nothing

Here is the HTMLCellFormatting:
Private Sub oPdfExporter_HTMLCellFormatting(ByVal sender As Object, ByVal e As Telerik.WinControls.UI.Export.HTML.HTMLCellFormattingEventArgs)
    If e.GridColumnIndex = 1 AndAlso e.GridRowInfoType.Equals(GetType(GridViewDataRowInfo)) Then
        e.HTMLCellElement.Value = "Test value"
        e.HTMLCellElement.Styles.Add("background-color", ColorTranslator.ToHtml(Color.Orange))
    End If
End Sub

Any ideas why the the oPdfExporter_HTMLCellFormatting event is not raised?

Thanks.

1 Answer, 1 is accepted

Sort by
0
Accepted
Richard Slade
Top achievements
Rank 2
answered on 31 May 2011, 10:23 AM
Hello,

It looks as though you are missing adding a handles or AddHandler. Here is a full sample for you to try.

Form1 Designer File
<Global.Microsoft.VisualBasic.CompilerServices.DesignerGenerated()> _
Partial Class Form1
    Inherits System.Windows.Forms.Form
  
    'Form overrides dispose to clean up the component list.
    <System.Diagnostics.DebuggerNonUserCode()> _
    Protected Overrides Sub Dispose(ByVal disposing As Boolean)
        Try
            If disposing AndAlso components IsNot Nothing Then
                components.Dispose()
            End If
        Finally
            MyBase.Dispose(disposing)
        End Try
    End Sub
  
    'Required by the Windows Form Designer
    Private components As System.ComponentModel.IContainer
  
    'NOTE: The following procedure is required by the Windows Form Designer
    'It can be modified using the Windows Form Designer.  
    'Do not modify it using the code editor.
    <System.Diagnostics.DebuggerStepThrough()> _
    Private Sub InitializeComponent()
        Me.RadGridView1 = New Telerik.WinControls.UI.RadGridView()
        Me.RadButtonExport = New Telerik.WinControls.UI.RadButton()
        CType(Me.RadGridView1, System.ComponentModel.ISupportInitialize).BeginInit()
        CType(Me.RadButtonExport, System.ComponentModel.ISupportInitialize).BeginInit()
        Me.SuspendLayout()
        '
        'RadGridView1
        '
        Me.RadGridView1.Location = New System.Drawing.Point(12, 13)
        Me.RadGridView1.Name = "RadGridView1"
        Me.RadGridView1.Size = New System.Drawing.Size(320, 286)
        Me.RadGridView1.TabIndex = 0
        Me.RadGridView1.Text = "RadGridView1"
        '
        'RadButtonExport
        '
        Me.RadButtonExport.Location = New System.Drawing.Point(245, 305)
        Me.RadButtonExport.Name = "RadButtonExport"
        Me.RadButtonExport.Size = New System.Drawing.Size(87, 24)
        Me.RadButtonExport.TabIndex = 2
        Me.RadButtonExport.Text = "Export"
        '
        'Form1
        '
        Me.AutoScaleDimensions = New System.Drawing.SizeF(6.0!, 13.0!)
        Me.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font
        Me.ClientSize = New System.Drawing.Size(346, 337)
        Me.Controls.Add(Me.RadButtonExport)
        Me.Controls.Add(Me.RadGridView1)
        Me.Name = "Form1"
        Me.Text = "Form1"
        CType(Me.RadGridView1, System.ComponentModel.ISupportInitialize).EndInit()
        CType(Me.RadButtonExport, System.ComponentModel.ISupportInitialize).EndInit()
        Me.ResumeLayout(False)
  
    End Sub
    Friend WithEvents RadGridView1 As Telerik.WinControls.UI.RadGridView
    Friend WithEvents RadButtonExport As Telerik.WinControls.UI.RadButton
  
End Class

Form1.vb
Imports Telerik.WinControls.UI
Imports Telerik.WinControls
Imports Telerik.Data
Imports System.ComponentModel
Imports Telerik.WinControls.UI.Export
  
  
  
Public Class Form1
  
    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Me.RadGridView1.AutoSizeColumnsMode = GridViewAutoSizeColumnsMode.Fill
        Dim list As New BindingList(Of Person)()
        For i As Integer = 0 To 50
            list.Add(New Person("Name " & i.ToString(), "Description " & i.ToString(), i, True))
        Next
        Me.RadGridView1.DataSource = list
    End Sub
  
    Private Sub RadButtonExcel_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles RadButtonExport.Click
        Dim export As New ExportToPDF(Me.RadGridView1)
        AddHandler export.HTMLCellFormatting, AddressOf Export_HTMLCellFormatting
        export.RunExport("Your file path...\MyFile.csv")
    End Sub
  
    Private Sub Export_HTMLCellFormatting(ByVal sender As Object, ByVal e As Telerik.WinControls.UI.Export.HTML.HTMLCellFormattingEventArgs)
        If e.InnerCellValue IsNot Nothing Then
            Debug.WriteLine(e.InnerCellValue.ToString())
        End If
    End Sub
  
End Class
  
Public Class Person
    Public Sub New(ByVal name As String, ByVal description As String, ByVal id As Integer, ByVal hasBeard As Boolean)
        Me.Name = name
        Me.Description = description
        Me.Id = id
        Me.HasBeard = hasBeard
    End Sub
  
    Public Property Name As String
    Public Property Description As String
    Public Property Id As Integer
    Public Property HasBeard As Boolean
End Class

hope that helps
Richard
Tags
GridView
Asked by
Joel Jordan
Top achievements
Rank 1
Answers by
Richard Slade
Top achievements
Rank 2
Share this question
or