Reputation: 41
I would like to export datagridview table to pdf. But when I execute my application it takes the first column of the datagridview while I don't want the first column to be taken.
Here is the code that add the column. I don't want it to take the first column.
'Adding Header row
For Each column As DataGridViewColumn In DataGridView1.Columns
Dim cell As New PdfPCell(New Phrase(column.HeaderText, font12Bold))
'cell.BackgroundColor = New iTextSharp.text.Color(240, 240, 240)
cell.HorizontalAlignment = PdfPCell.ALIGN_CENTER
PdfTable.AddCell(cell)
Next
Upvotes: 0
Views: 183
Reputation: 216348
Use a normal for ... loop instead of a for each... and start from the second column (1)
For x = 1 To DataGridView1.Columns.Count - 1
Dim column = DataGridView1.Columns(x)
Dim cell As New PdfPCell(New Phrase(column.HeaderText, font12Bold))
cell.HorizontalAlignment = PdfPCell.ALIGN_CENTER
PdfTable.AddCell(cell)
Next
Upvotes: 1