We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback


Thread ID:





141924 Jan 10,2019 03:21 PM UTC Jan 11,2019 12:15 PM UTC WinForms 1
Tags: SfDataGrid
Asked On January 10, 2019 03:21 PM UTC



1. How to change backgound colour of Cell for Group/Subgroup.. for Export to Excel as well as Export to PDF

Example :

If In Drag Group area If we have selected 5 Fields.. Col A, Col B, Col C, Col D and Col E

In Grid Data Area How Background Cell Color for A Field Groupwise = A Color, for B Field Groupwise (Subgroup) = B Color, for C Field Groupwise (Subgroup of B) = C Colour... on and on..

Please check the attached Excel Sheet with Current Result and Expected Result in REQUIRED RESULT-1 sheet

2. In Group result, field name with Field value of selected field for Grouping is required. 

Please check the attached Excel Sheet with Current Result and Expected Result in REQUIRED RESULT-2 sheet.

Please note that  both the result required while export to Excel and Export to PDF also.

Hope that you will understand and do the needful.

Attachment: bank_master_demo_4b85841a.rar

Jayaleshwari N [Syncfusion]
Replied On January 11, 2019 12:15 PM UTC

Hi Deepak, 
We have checked the reported queries. Please find the details as following. 
Set background color to each group based on the level in grid 
You can achieve your requirement by using DrawCell eventby checking the RowType as CaptionCoveredRow 
private void SfDataGrid1_DrawCell(object sender, DrawCellEventArgs e) 
    if (e.DataRow.RowType == RowType.CaptionCoveredRow) 
        var level = (e.DataRow.RowData as Group).Level; 
        if (level == 1) 
            e.Style.BackColor = Color.YellowGreen; 
        else if (level == 2) 
            e.Style.BackColor = Color.AliceBlue; 
        else if (level == 3) 
            e.Style.BackColor = Color.IndianRed; 
You can refer the following user guide documentation to customize the caption summary cell. 
In Group result, field name with Field value of selected field for Grouping is required.  
By default our SfDataGrid displays the group header with column name along with summary value. 
You can refer the following screen shot. 
How to change backgound colour of Cell for Group/Subgroup.. for Export to Excel as well as Export to PDF 
You can achieve this requirement by customizing the converter. You can refer the following code snippets. 
Exporting to excel. 
public class SfDataGridExcelConvereter    : DataGridToExcelConverter 
    int level = -1; 
    protected override void ExportGroupCaptionToExcel(SfDataGrid grid, ICollectionViewAdv view, IWorksheet sheet, ExcelExportingOptions excelExportingOptions, Group group) 
        level = group.Level; 
        base.ExportGroupCaptionToExcel(grid, view, sheet, excelExportingOptions, group); 
    protected override void ExportSummaryCellToExcel(SfDataGrid grid, IRange summaryRange, ExportCellType exportCellType, string summaryDisplayText, object exportNodeEntry, string columnName, ExcelExportingOptions excelExportingOptions) 
        base.ExportSummaryCellToExcel(grid, summaryRange, exportCellType, summaryDisplayText, exportNodeEntry, columnName, excelExportingOptions); 
        if (level == 1) 
            summaryRange.CellStyle.FillBackground = ExcelKnownColors.Green; 
        else if (level == 2) 
            summaryRange.CellStyle.FillBackground = ExcelKnownColors.Blue; 
        else if (level == 3) 
            summaryRange.CellStyle.FillBackground = ExcelKnownColors.Red; 
        level = -1; 
private void ExportToExcel_Click(object sender, EventArgs e) 
    var options = new ExcelExportingOptions(); 
    var excelConverter = new SfDataGridExcelConvereter(); 
    var excelEngine = excelConverter.ExportToExcel(sfDataGrid1, sfDataGrid1.View, options);             
    var workBook = excelEngine.Excel.Workbooks[0]; 
Exporting to PDF 
public class SfDataGridPDFConvereter    : DataGridToPdfConverter 
    int level = -1; 
    protected override void ExportGroupCaptionToPdf(SfDataGrid sfgrid, PdfGrid pdfGrid, ICollectionViewAdv view, PdfExportingOptions pdfExportingOptions, Group group) 
        level = group.Level; 
        base.ExportGroupCaptionToPdf(sfgrid, pdfGrid, view, pdfExportingOptions, group);             
    protected override void ExportSummaryCellToPdf(SfDataGrid sfGrid, PdfGridCell pdfGridCell, PdfExportingOptions pdfExportingOptions, ExportCellType exportCellType, string summaryDisplayText, object exportNodeEntry, string columnName) 
        base.ExportSummaryCellToPdf(sfGrid, pdfGridCell, pdfExportingOptions, exportCellType, summaryDisplayText, exportNodeEntry, columnName); 
        if (level == 1) 
            pdfGridCell.Style.BackgroundBrush = PdfBrushes.YellowGreen; 
        else if (level == 2) 
            pdfGridCell.Style.BackgroundBrush = PdfBrushes.AliceBlue; 
        else if (level == 3) 
            pdfGridCell.Style.BackgroundBrush = PdfBrushes.IndianRed; 
        level = -1; 
private void ExportToPDF_Click(object sender, EventArgs e) 
    PdfExportingOptions options = new PdfExportingOptions();            
    var pdfConverter = new SfDataGridPDFConvereter(); 
    var document = pdfConverter.ExportToPdf(sfDataGrid1,options);                       
We have attached the sample for your reference and it is available in the following location.  
Please let us know if you would require further assistance. 
Jayaleshwari N. 


This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

Please sign in to access our forum

This page will automatically be redirected to the sign-in page in 10 seconds.

Warning Icon You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.Close Icon

Live Chat Icon For mobile
Live Chat Icon