Edit this page

Get the Column of The Corresponding Cell

When a cell(header cell, cell, footer cell, group footer cells) is exported through the ExportToXlsx or ExportToPdf methods , the arguments of the ElementExportingToDocument event can be cast to GridViewCellExportingEventArgs. Thus, the column of the corresponding cell can be accessed.

The following example illustrates the approach:

Example 3: Getting the Column of the Corresponding Cell

this.gridViewExport.ElementExportingToDocument += (s, e) =>
{
    if (e.Element == ExportElement.Cell)
    {
        var cellExportingArgs = e as GridViewCellExportingEventArgs;
        if (cellExportingArgs.Column == this.gridViewExport.Columns[2])
        {
            (cellExportingArgs.VisualParameters as GridViewDocumentVisualExportParameters).Style = cellStyle;
        }
    }
};

[VB.NET] Example 3: Getting the Column of the Corresponding Cell

Me.gridViewExport.ElementExportingToDocument += Function(s, e) 
    If e.Element = ExportElement.Cell Then
        Dim cellExportingArgs = TryCast(e, GridViewCellExportingEventArgs)
            If cellExportingArgs.Column = Me.gridViewExport.Columns(2) Then
                TryCast(cellExportingArgs.VisualParameters, GridViewDocumentVisualExportParameters).Style = cellStyle
            End If
    End If
End Function