Click here to Skip to main content
15,885,032 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I know this is the code to insert all of a datagridview into a PDF file :
C#
iTextSharp.text.Font fontTable = FontFactory.GetFont("Arial", 8, iTextSharp.text.Font.NORMAL, BaseColor.BLACK);

        PdfPTable table = new PdfPTable(dataGridView1.Columns.Count);
        table.SpacingBefore = 45f;
        table.TotalWidth = 300;
        table.DefaultCell.Phrase = new Phrase() { Font = fontTable };

        for (int j = 0; j < dataGridView1.Columns.Count; j++)
        {
            table.AddCell(new Phrase(dataGridView1.Columns[j].HeaderText, fontTable));

        }

        table.HeaderRows = 1;

        for (int i = 0; i < dataGridView1.Rows.Count; i++)
        {
            for (int k = 0; k < dataGridView1.Columns.Count; k++)
            {
                if (dataGridView1[k, i].Value != null)
                {
                    table.AddCell(new Phrase(dataGridView1[k, i].Value.ToString(),fontTable));
                }
            }
        }



        doc.Add(table);


And someone suggested this to me :
C#
foreach (DataGridViewColumn c in GridView.Columns)
{
    if( c.Name == "Something" )
    {
        //Skip this column
        continue;
    }

    //process these columns
    //..
}

for (int i = 0; i < GridView.Rows.Count - 1; i++)
{
    for (int j = 0; j < GridView.Columns.Count - 1; j++)
    {
        if( GridView.Columns[j].Name == "Something" )
        {
            //Skip this column
            continue
        }

        //Process these columns
    }
}

To only show specific columns. Any suggestions where I'm going wrong?
Posted
Comments
[no name] 15-Jul-14 20:22pm    
"Any suggestions where I'm going wrong", telling you where you have gone wrong presupposes that we have the ability to look over your shoulder and see whatever it is on your screen that you think is "wrong". We would have no idea what you think is "right" or "wrong".
Member 10606164 16-Jul-14 6:50am    
I'll rephrase, any suggestions why my code doesn't work. E.g it doesn't display the table on the PDF document.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900