title: How to merge first 3 columns for rows with same value in PDF
body: <p>I'm using <code>itextSharp</code> to export a DataTable to a pdf table. I can export the data to a pdf table using the sample code i have posted below. The DataTable contains close to 21 columns.</p>
  
  <p>The first column in the pdf (DataTable) might contain similar values for any number of rows. If the data values in first column for a group of rows is similar, i want to merge the first 3 columns of those rows as one cell. </p>
  
  <p>I'm having trouble modifying the code below to achieve this.</p>
  
  <pre><code>public iTextSharp.text.Table GetItextTable(DataTable dtChartData, string reportType)
      {
          int intCols = dtChartData.Columns.Count; //Total number of columns 
          int intRows = dtChartData.Rows.Count; //Total number of rows 
          iTextSharp.text.Table pdfTable = new iTextSharp.text.Table(intCols, intRows);
          try
          {
              pdfTable.BorderWidth = 1;
              pdfTable.Width = 100;
              pdfTable.Padding = 1;
              pdfTable.Spacing = 1;
              /*creating table headers */
              for (int i = 0; i &lt; intCols; i++)
              {
  
                  iTextSharp.text.Cell cellCols = new iTextSharp.text.Cell();
                  iTextSharp.text.Font ColFont = iTextSharp.text.FontFactory.GetFont("Tahoma", 07,
                      iTextSharp.text.Font.BOLD);
                  for (int l = 0; l &lt; dtChartData.Columns.Count; l++)
                  {
                      if (dtChartData.Columns[l].ColumnName.Contains("_"))
                      {
                          dtChartData.Columns[l].ColumnName = dtChartData.Columns[l].ColumnName.Replace("_", " ");
                      }
                  }
                  iTextSharp.text.Chunk chunkCols = new iTextSharp.text.Chunk(dtChartData.Columns[i].ColumnName,ColFont);
                  cellCols.HorizontalAlignment = iTextSharp.text.Element.ALIGN_CENTER;
                  if ((chunkCols.ToString().ToLower() == "ReportDetails"))
                  {
                      cellCols.HorizontalAlignment = iTextSharp.text.Element.ALIGN_CENTER;
                  }
              }
              /* loop that take values from every row in datatable and insert in itextsharp table */
              for (int k = 0; k &lt; intRows; k++)
              {
                  for (int j = 0; j &lt; intCols; j++)
                  {
                      iTextSharp.text.Cell cellRows = new iTextSharp.text.Cell();
                      iTextSharp.text.Font RowFont = iTextSharp.text.FontFactory.GetFont("Tahoma", 07);
                      iTextSharp.text.Chunk chunkRows = new iTextSharp.text.Chunk(dtChartData.Rows[k][j].ToString(),RowFont);
  
                      cellRows.HorizontalAlignment = iTextSharp.text.Element.ALIGN_CENTER;
                      cellRows.Add(chunkRows);
                      pdfTable.AddCell(cellRows);
                  }
              }
          }
          catch (Exception ex)
          {
              //error handling code here removed
          }
          return pdfTable;
      }
  </code></pre>