Articles in this section

How to achieve AlternateRowBackground in exporting .NET MAUI DataGrid (SfDataGrid) ?

In this article, we will show you how to achieve alternate row background in .NET MAUI DataGrid Exporting.

Please note that exporting does not support AlternateRowBackground in the MAUI SfDataGrid. However, you can achieve alternate row background color using the RowExporting event.

C#
The code below illustrates how to achieve an alternate row background in DataGrid PDF exporting.

private void Button_Clicked(object sender, EventArgs e)
{
    MemoryStream stream = new MemoryStream();
    DataGridPdfExportingController pdfExport = new DataGridPdfExportingController();
    pdfExport.RowExporting += pdfExport_RowExporting;
    DataGridPdfExportingOption option = new DataGridPdfExportingOption();
    var pdfDoc = new PdfDocument();
    pdfDoc = pdfExport.ExportToPdf(this.dataGrid, option);
    pdfDoc.Save(stream);
    pdfDoc.Close(true);
    SaveService saveService = new();
    saveService.SaveAndView("ExportFeature.pdf", "application/pdf", stream);
}

void pdfExport_RowExporting(object sender, DataGridRowPdfExportingEventArgs e)
{
    if (e.RowType == ExportRowType.RecordRow)
    {
        var index = dataGrid?.View?.Records.IndexOf(e.Record);
        if (index % 2 == 0)
        {
            e.PdfRow.Style.BackgroundBrush = PdfBrushes.Yellow;
        }
        else
        {
            e.PdfRow.Style.BackgroundBrush = PdfBrushes.Transparent;
        }
    }
}

Output

PdfExport.png

Download the complete sample from GitHub

Conclusion

I hope you enjoyed learning how to achieve an alternate row background in .NET MAUI DataGrid.

You can refer to our .NET MAUI DataGrid feature tour page to learn about its other groundbreaking feature representations. Explore our .NET MAUI DataGrid Documentation to understand how to present and manipulate data.

For current customers, check out our .NET MAUI components on the License and Downloads page. If you are new to Syncfusion®, try our 30-day free trial to explore our .NET MAUI DataGrid and other .NET MAUI components.

Please let us know in the comments section if you have any queries or require clarification. You can also contact us through our support forums, Direct-Trac or feedback portal, or the feedback portal. We are always happy to assist you!

Did you find this information helpful?
Yes
No
Help us improve this page
Please provide feedback or comments
Comments (0)
Access denied
Access denied