none
Header with two rows in a grid, need different colors and font RRS feed

  • Question

  • Hello , All

    I have a grid for displaying data in which I have header with two rows and I need different colors and fonts for each header row , then how to set separately?  Any help will be appreciated.sorry choose wrong type of questions.That's in PDF.


    • Edited by Ulyadam Wednesday, May 6, 2015 3:22 AM PDF
    Wednesday, May 6, 2015 3:18 AM

Answers

  • Try change the code:

    PdfTrueTypeFont firstHeaderRowFont = new PdfTrueTypeFont(new Font("Arial", 10f, FontStyle.Bold));
    PdfTrueTypeFont secondHeaderRowFont = new PdfTrueTypeFont(new Font("Arial", 7f, FontStyle.Bold));
    PdfTrueTypeFont bodyRowFont = new PdfTrueTypeFont(new Font("Arial", 6f));

    to 

    PdfFont firstHeaderRowFont = new PdfFont(PdfFontFamily.Helvetica, 10f, PdfFontStyle.Bold);
    PdfFont secondHeaderRowFont = new PdfFont(PdfFontFamily.Helvetica, 7f, PdfFontStyle.Bold);
    PdfFont bodyRowFont = new PdfFont(PdfFontFamily.Helvetica, 6f);

    Working fine now,thank u.
    • Marked as answer by Ulyadam Wednesday, May 6, 2015 3:36 AM
    Wednesday, May 6, 2015 3:36 AM

All replies

  • U can try this PDF library add reference to you project then add the following code

    headerRow.Cells[0].Style.Font = firstHeaderRowFont;
    headerRow.Cells[0].ColumnSpan = grid.Columns.Count;
    headerRow.Cells[0].Style.BackgroundBrush = new PdfSolidBrush(new PdfRGBColor(217, 217, 217));
    
    PdfGridRow headerRow2 = grid.Headers.Add(1)[1];
    
    for (int i = 0; i < header.Length; i++)
    {
          headerRow2.Cells[i].Value = header[i];
          headerRow2.Cells[i].StringFormat = centerFormat;
          headerRow2.Cells[i].Style.Borders = border;
          headerRow2.Cells[i].Style.Font = secondHeaderRowFont;
          headerRow2.Cells[i].Style.Borders = border;
          headerRow2.Cells[i].Style.BackgroundBrush = new PdfSolidBrush(new PdfRGBColor(255, 255, 204));
    }
    
    ...
    

    Wednesday, May 6, 2015 3:30 AM
  • U can try this PDF library add reference to you project then add the following code

    headerRow.Cells[0].Style.Font = firstHeaderRowFont;
    headerRow.Cells[0].ColumnSpan = grid.Columns.Count;
    headerRow.Cells[0].Style.BackgroundBrush = new PdfSolidBrush(new PdfRGBColor(217, 217, 217));
    
    PdfGridRow headerRow2 = grid.Headers.Add(1)[1];
    
    for (int i = 0; i < header.Length; i++)
    {
          headerRow2.Cells[i].Value = header[i];
          headerRow2.Cells[i].StringFormat = centerFormat;
          headerRow2.Cells[i].Style.Borders = border;
          headerRow2.Cells[i].Style.Font = secondHeaderRowFont;
          headerRow2.Cells[i].Style.Borders = border;
          headerRow2.Cells[i].Style.BackgroundBrush = new PdfSolidBrush(new PdfRGBColor(255, 255, 204));
    }
    
    ...

    I have tried,but font is acting weird.AsI can see from code set "firstHeaderRowFont" for first header row font and "secondHeaderRowFont" for second row and very often happens that font in first row gets overridden by font in second. I am not sure but I think that is somehow connected with font style because behavior changes if I change styles for "firstHeaderRowFont" and "secondHeaderRowFont" 
    Wednesday, May 6, 2015 3:32 AM
  • Try change the code:

    PdfTrueTypeFont firstHeaderRowFont = new PdfTrueTypeFont(new Font("Arial", 10f, FontStyle.Bold));
    PdfTrueTypeFont secondHeaderRowFont = new PdfTrueTypeFont(new Font("Arial", 7f, FontStyle.Bold));
    PdfTrueTypeFont bodyRowFont = new PdfTrueTypeFont(new Font("Arial", 6f));
    

    to 

    PdfFont firstHeaderRowFont = new PdfFont(PdfFontFamily.Helvetica, 10f, PdfFontStyle.Bold);
    PdfFont secondHeaderRowFont = new PdfFont(PdfFontFamily.Helvetica, 7f, PdfFontStyle.Bold);
    PdfFont bodyRowFont = new PdfFont(PdfFontFamily.Helvetica, 6f);
    

    Wednesday, May 6, 2015 3:35 AM
  • Try change the code:

    PdfTrueTypeFont firstHeaderRowFont = new PdfTrueTypeFont(new Font("Arial", 10f, FontStyle.Bold));
    PdfTrueTypeFont secondHeaderRowFont = new PdfTrueTypeFont(new Font("Arial", 7f, FontStyle.Bold));
    PdfTrueTypeFont bodyRowFont = new PdfTrueTypeFont(new Font("Arial", 6f));

    to 

    PdfFont firstHeaderRowFont = new PdfFont(PdfFontFamily.Helvetica, 10f, PdfFontStyle.Bold);
    PdfFont secondHeaderRowFont = new PdfFont(PdfFontFamily.Helvetica, 7f, PdfFontStyle.Bold);
    PdfFont bodyRowFont = new PdfFont(PdfFontFamily.Helvetica, 6f);

    Working fine now,thank u.
    • Marked as answer by Ulyadam Wednesday, May 6, 2015 3:36 AM
    Wednesday, May 6, 2015 3:36 AM