Customise Printing of cell borders between StackedHeaderRow and a ChildColumn of SfDataGrid

When Printing the SfDataGrid, is it possible to remove cell borders from between a StackedHeaderRow  and the ChildColumn directly below it so that when you have only one ChildColumn there is only a perimeter border around the combined StackedHeaderRow  and its ChildColumn?
In XAML, the StackedHeaderRow  border would be "1,1,1,0" (no bottom border) and the ChildColumn would be "1,0,1,1" (no top border).

Thanks.

3 Replies

GT Gnanasownthari Thirugnanam Syncfusion Team March 26, 2018 05:29 PM UTC

Hi Adrian, 

You can remove the bottom border of StackedHeaderRow by customize the OnRenderRow method in GridPrintManager like below code example. 
 
protected override void OnRenderRow(DrawingContext drawingContext, RowInfo rowInfoList) 
    { 
        var cellsInfo = rowInfoList.CellsInfo; 
        //when we draw the cell for PrintStackedHeader=True we can't able to print it by normal way because the Stacked Header size is varied from one to another. 
        if (rowInfoList.RowType == RowType.StackedHeaderRow  && CanPrintStackedHeaders) 
        { 
            for (int i = 0; i < cellsInfo.Count; i++) 
            { 
                OnRenderCell(drawingContext, rowInfoList, cellsInfo[i]); 
                //Last Cell Right Border 
                if (cellsInfo[i].Equals(cellsInfo[cellsInfo.Count - 1])) 
                    drawingContext.DrawLine(new Pen(Brushes.Black, 1), cellsInfo[i].CellRect.TopRight, cellsInfo[i].CellRect.BottomRight);   //Last cell Right border 
                if (rowInfoList.NeedTopBorder) 
                    //Top border of the page 
                    drawingContext.DrawLine(new Pen(Brushes.Black, 1), cellsInfo[i].CellRect.TopLeft, cellsInfo[i].CellRect.TopRight); 
                if (rowInfoList.NeedBottomBorder) 
                    if (rowInfoList.CellsInfo[0].CellRect.Height > 0) 
                        //Row Bottom Border 
                        drawingContext.DrawLine(new Pen(Brushes.Black, 1), cellsInfo[i].CellRect.BottomLeft, cellsInfo[i].CellRect.BottomRight); 
            } 
        } 
        else if (rowInfoList.RowType == RowType.HeaderRow) 
        { 
            for (int i = 0; i < cellsInfo.Count; i++) 
            { 
                OnRenderCell(drawingContext, rowInfoList, cellsInfo[i]); 
                //Last Cell Right Border 
                if (cellsInfo[i].Equals(cellsInfo[cellsInfo.Count - 1])) 
                    drawingContext.DrawLine(new Pen(Brushes.Black, 1), cellsInfo[i].CellRect.TopRight, cellsInfo[i].CellRect.BottomRight);   //Last cell Right border 
                if (cellsInfo[i].ColumnName == "CustomerName") 
                    //Top border of the page 
                    drawingContext.DrawLine(new Pen(Brushes.Black, 1), cellsInfo[i].CellRect.TopLeft, cellsInfo[i].CellRect.TopRight); 
                if (rowInfoList.NeedBottomBorder) 
                    if (rowInfoList.CellsInfo[0].CellRect.Height > 0) 
                        //Row Bottom Border 
                        drawingContext.DrawLine(new Pen(Brushes.Black, 1), cellsInfo[i].CellRect.BottomLeft, cellsInfo[i].CellRect.BottomRight); 
            } 
        } 
                  
        else 
        { 
            foreach (var cellInfo in cellsInfo) 
            { 
                OnRenderCell(drawingContext, rowInfoList, cellInfo); 
                //Last Cell Right Border 
                if (cellInfo.Equals(cellsInfo[cellsInfo.Count - 1])) 
                    drawingContext.DrawLine(new Pen(Brushes.Black, 1), cellInfo.CellRect.TopRight, cellsInfo[cellsInfo.Count - 1].CellRect.BottomRight);   //Last cell Right border 
            } 
            if (rowInfoList.NeedTopBorder) 
                //Top border of the page 
                drawingContext.DrawLine(new Pen(Brushes.Black, 1), cellsInfo[0].CellRect.TopLeft, cellsInfo[cellsInfo.Count - 1].CellRect.TopRight); 
            if (rowInfoList.NeedBottomBorder) 
                if (rowInfoList.CellsInfo[0].CellRect.Height > 0) 
                    //Row Bottom Border 
                    drawingContext.DrawLine(new Pen(Brushes.Black, 1), cellsInfo[0].CellRect.BottomLeft, cellsInfo[cellsInfo.Count - 1].CellRect.BottomRight); 
        } 
    } 
} 

We have prepared the sample based on your requirement, you can download it from below mentioned location. 


Please let us know if you need further assistance on this, we will happy to assist you. 

Regards, 
Gnanasownthari T. 

 



AD Adrian March 29, 2018 10:10 AM UTC

Thanks for the solution Gnanasownthari T., works a treat!
Regards,
Adrian



JG Jai Ganesh S Syncfusion Team March 30, 2018 12:46 AM UTC

Hi Adrian, 
 
Thank you for the update. 
 
Please let us know if you need further assistance on this. 
 
Regards, 
Jai Ganesh S 
 


Loader.
Up arrow icon