Reputation: 503
I've four columns in a datagridview
. When I select some rows from that datagridview
and hit a button or something I want to create a pdf table consisting of those selected rows but ignore the column 2 data in the pdf table. How can I do that?
Sample code I've done (which shows all 4 columns data):
foreach (DataGridViewColumn column in dataGridView1.Columns)
{
PdfPCell cell = new PdfPCell(new Phrase(column.HeaderText,headerFont));
cell.BackgroundColor = new BaseColor(215, 20, 130);
cell.Border=0;
pdfTable.AddCell(cell);
}
foreach (DataGridViewRow row in dataGridView1.SelectedRows)
{
foreach (DataGridViewCell cell in row.Cells)
{
pdfTable.AddCell(new Phrase(cell.Value.ToString(),standardFont));
}
}
But, I don't want the 2nd column data to be exported to the pdf.
Can you help me to solve this problem? Thank you.
Upvotes: 0
Views: 325
Reputation: 1519
int i = 0;
foreach (DataGridViewColumn column in dataGridView1.Columns)
{
i++;
if(i == 2) continue;
PdfPCell cell = new PdfPCell(new Phrase(column.HeaderText,headerFont));
cell.BackgroundColor = new BaseColor(215, 20, 130);
cell.Border=0;
pdfTable.AddCell(cell);
}
foreach (DataGridViewRow row in dataGridView1.SelectedRows)
{
i = 0;
foreach (DataGridViewCell cell in row.Cells)
{
i++;
if(i == 2) continue;
pdfTable.AddCell(new Phrase(cell.Value.ToString(),standardFont));
}
}
Upvotes: 2