styling PdfGrid

I am trying to style the borders of the header cells in a PdfGrid. I use the code below. Everything works ok, except the left border of the first cell of the header is not colored correctly. There seems to be no border at all. How can I fix that?

            // DetailsList-Grid, set data source

            PdfGrid detailsGrid = new PdfGrid();

            detailsGrid.DataSource = detailsList;


            detailsGrid.Headers[0].Cells[0].Value = "In Solution";

            detailsGrid.Headers[0].Cells[1].Value = "As Part Of";

            detailsGrid.Headers[0].Cells[2].Value = "Used On";

            detailsGrid.Headers[0].Cells[3].Value = "Expiry Date";

            detailsGrid.Headers[0].Cells[4].Value = "Ued By";

            detailsGrid.Headers[0].Cells[5].Value = "Study Name";

            detailsGrid.Headers[0].Cells[6].Value = "Project Name";


            // Header

            PdfGridRow header = detailsGrid.Headers[0];

            header.Height = 40;


            PdfGridCellStyle headerCellStyle = new PdfGridCellStyle();

            headerCellStyle.BackgroundBrush = PdfBrushes.Blue;

            headerCellStyle.Borders.Top = new PdfPen(Color.Blue);

            headerCellStyle.Borders.Bottom = new PdfPen(Color.White);


            headerCellStyle.Font = new PdfStandardFont(PdfFontFamily.Courier, 10);

            headerCellStyle.TextPen = PdfPens.White;


            for (int i = 0; i < header.Cells.Count; i++)

            {

                //Get the cell.

                PdfGridCell cell = header.Cells[i];


                if (i == 0)

                {

                    headerCellStyle.Borders.Left = new PdfPen(Color.Red);

                    headerCellStyle.Borders.Right = new PdfPen(Color.White);

                    headerCellStyle.Borders.Left.Width = 5;

                    headerCellStyle.Borders.Right.Width = 5;

                }


                if (i == header.Cells.Count - 1)

                {

                    headerCellStyle.Borders.Right = new PdfPen(Color.Red);

                    headerCellStyle.Borders.Left = new PdfPen(Color.White);

                    headerCellStyle.Borders.Left.Width = 5;

                    headerCellStyle.Borders.Right.Width = 5;

                }


                if (i >= 1 && i < header.Cells.Count - 1)

                {

                    headerCellStyle.Borders.Right = new PdfPen(Color.White);

                    headerCellStyle.Borders.Left = new PdfPen(Color.White);

                    headerCellStyle.Borders.Left.Width = 5;

                    headerCellStyle.Borders.Right.Width = 5;

                }



                //Apply the cell style.

                cell.Style = headerCellStyle;

            }

Best regards


Hucky




7 Replies

JT Jeyalakshmi Thangamarippandian Syncfusion Team April 22, 2024 07:28 AM UTC

Hi Hucky,

We were able to reproduce the reported issue with the provided details on our end, and currently we are analyzing it. We will provide further details on April 24th, 2024.


Regards,

Jeyalakshmi T




MK Moorthy Karunanithi Syncfusion Team April 24, 2024 03:25 PM UTC

The reported issues still need a lot more in-depth research; thus, we are looking into them. On April 26th, 2024, further information will be updated.



JT Jeyalakshmi Thangamarippandian Syncfusion Team April 25, 2024 02:32 PM UTC

Upon further analysis, we observed that the sample you provided only contains a single instance of the header style. This may result in overwriting the existing header style. To address this issue, we have created a new sample. Please refer to the sample below.

 

Sample Link: https://www.syncfusion.com/downloads/support/directtrac/general/ze/StyleGridIssue-1420945429



HA Hartmut replied to Jeyalakshmi Thangamarippandian April 25, 2024 03:17 PM UTC

Dear Jeyalakshmi,

I applied your code and it works. I still do not understand why part of the formatting was applied correctly (e. g. background brush) and others not, but it's okay as it works.


May I ask another question: In the corresponding program file I have "using Syncfusion.Pdf.Grid;" at the top. When I add some of the styling VS2022 automatically adds "using Syncfusion.PdfExport;". This usually generates a lot of errors because of ambiguities for the two namespaces. Deactivating "using Syncfusion.PdfExport;" solves the errors. Why are there two namespaces, and which to use preferably? Obviously, "using Syncfusion.PdfExport;" does not comprise all commands that are in "using Syncfusion.Pdf.Grid;"


Hartmut



JT Jeyalakshmi Thangamarippandian Syncfusion Team April 26, 2024 10:19 AM UTC

Hi Hartmut,

We have recommend to use our Syncfusion.Pdf.Net.Core NuGet package, which is the feature rich library for handling PDF related functionalities. Additionally, the Syncfusion.PdfExport package is an internal package specifically designed for exporting grids to PDF with limited feature sets.


Regards,

Jeyalakshmi T



SE Salvador Earls May 15, 2024 08:44 AM UTC

Ok, thanks. I will use it and if I face any issue, I will update by starting my own thread.



JT Jeyalakshmi Thangamarippandian Syncfusion Team May 16, 2024 11:21 AM UTC

Thank you for the update, please get back to us if you need any further assistance on this. 


Loader.
Up arrow icon