Completed
Last Updated: 12 Feb 2018 09:12 by Don
ADMIN
Hristo
Created on: 02 Mar 2017 07:58
Category: GridView
Type: Feature Request
2
IMPROVE. RadGridView - GridViewPdfExport should respect the format string applied to the GridViewDataColumn
Workaround: handle the GridViewPdfExport.CellFormatting event and apply the column`s format string

Public Class Form1
    Sub New()

        InitializeComponent()

        Me.RadGridView1.DataSource = Me.GetData()
        Me.RadGridView1.AutoSizeColumnsMode = Telerik.WinControls.UI.GridViewAutoSizeColumnsMode.Fill

        Dim decimalColumn = DirectCast(Me.RadGridView1.Columns("Money"), GridViewDecimalColumn)
        decimalColumn.DecimalPlaces = 0
        decimalColumn.FormatString = "{0:C0}"

        Dim dateTimeColumn = DirectCast(Me.RadGridView1.Columns("Date"), GridViewDateTimeColumn)
        dateTimeColumn.FormatString = "{0:D}"

    End Sub

    Private Function GetData() As Object
        Dim dataTable As New DataTable()
        dataTable.Columns.Add("Id", GetType(Integer))
        dataTable.Columns.Add("Name", GetType(String))
        dataTable.Columns.Add("Money", GetType(Decimal))
        dataTable.Columns.Add("Date", GetType(DateTime))

        For i As Integer = 0 To 999
            dataTable.Rows.Add(i, "Name " & i, i * 10, DateTime.Now.AddDays(i))
        Next

        Return dataTable
    End Function

    Private Sub RadButton1_Click(sender As Object, e As EventArgs) Handles RadButton1.Click
        Dim pdfExporter = New GridViewPdfExport(Me.RadGridView1)
        AddHandler pdfExporter.CellFormatting, AddressOf pdfExporter_CellFormatting
        Dim renderer = New PdfExportRenderer()
        Dim fileName As String = "..\..\exported-grid.pdf"

        pdfExporter.RunExport(fileName, renderer)
    End Sub

    Private Sub pdfExporter_CellFormatting(sender As Object, e As PdfExportCellFormattingEventArgs)
        If e.RowIndex > -1 Then
            e.CellElement.Text = TryCast(RadDataConverter.Instance.Format(e.Row.Cells(e.ColumnIndex).Value, GetType(String), e.Column), String)
        End If
    End Sub

End Class
1 comment
Don
Posted on: 02 Mar 2017 14:57
The workaround worked perfectly! Thank you very much