pdfGridRow.Cells[i].Style.StringFormat is applied for all cell

Hi everyone,

I have implemented a function to generate a pdf by code. 
Now I am using  StringFormat to set the text allignment for each single cells.

For example:
     pdfGridRow.Cells[0].Style.StringFormat = new PdfStringFormat();
     pdfGridRow.Cells[0].Style.StringFormat.Alignment = PdfTextAlignment.Right;

     pdfGridRow.Cells[1].Style.StringFormat = new PdfStringFormat();
     pdfGridRow.Cells[1].Style.StringFormat.Alignment = PdfTextAlignment.Left;

But the pdf is generated the text into cellsa are aligned to left. In another words, the Cell[0] is also aligned to Left like Cell[1].
How to set up the text alignment for each cells?

Regards,
Achille

3 Replies

KC Karthikeyan Chandrasekar Syncfusion Team July 25, 2018 05:24 AM UTC

Hi Achille, 
Thank you for your interest in Syncfusion products. 
We are not able to reproduce the reported issue, the code snippet is working fine as expected. I have attached a working sample for your reference. Could you please refer this to resolve your issue, if you still faces the issue please modify our sample and revert me back. So that I could analysis in this and provide you a better solution. 

Regards, 
Karthikeyan  



AP Achille Penna July 25, 2018 12:47 PM UTC

Hi Karthikeyan  ,
thank you to reply my issue.
I have modified the example code to show you where my problem is  and when it is appears.
Now this code not work:
            pdfGrid.Rows[0].Cells[0].Style.StringFormat = new PdfStringFormat();
            pdfGrid.Rows[0].Cells[0].Style.StringFormat.Alignment = PdfTextAlignment.Left;
            pdfGrid.Rows[0].Cells[1].Style.StringFormat = new PdfStringFormat();
            pdfGrid.Rows[0].Cells[1].Style.StringFormat.Alignment = PdfTextAlignment.Right;

Regards,
Achille

Attachment: PdfGridAlignment29646396_26d6741.rar


KC Karthikeyan Chandrasekar Syncfusion Team July 30, 2018 09:15 AM UTC

Hi Achille, 
I have modified your code snippet below to achieve your requirement. 
PdfGridCellStyle cellStyle = new PdfGridCellStyle(); 
cellStyle.Borders.All = PdfPens.White; 
cellStyle.Font = new PdfStandardFont(PdfFontFamily.Helvetica, 6); 
cellStyle.TextBrush = PdfBrushes.Black; 
pdfGrid.Rows[0].ApplyStyle(cellStyle); 
 
//setting clone of the cell style to individual cell 
pdfGrid.Rows[0].Cells[0].Style = cellStyle.Clone() as PdfGridCellStyle; 
pdfGrid.Rows[0].Cells[0].Style.StringFormat = new PdfStringFormat(); 
pdfGrid.Rows[0].Cells[0].Style.StringFormat.Alignment = PdfTextAlignment.Left; 
 
 
//setting clone of the cell style to individual cell 
pdfGrid.Rows[0].Cells[1].Style = cellStyle.Clone() as PdfGridCellStyle; 
pdfGrid.Rows[0].Cells[1].Style.StringFormat = new PdfStringFormat(); 
pdfGrid.Rows[0].Cells[1].Style.StringFormat.Alignment = PdfTextAlignment.Right; 

Regards, 
Karthikeyan  


Loader.
Up arrow icon