Arny
Arny

Reputation:

Delete Columns from GridView

I have a GridView with a couple of columns that I do not want to be exported to PDF (through iTextSharp).

How can I hide the columns I don't want exported before I export the data?

Upvotes: 6

Views: 30811

Answers (3)

Wilhelm
Wilhelm

Reputation: 306

It is quite old but in the meantime there is another option:

myGridView.Columns.Remove(myGridView.Columns[3]) ;

or for vbnet:

myGridView.Columns.Remove(myGridView.Columns(3))

This removes the columns before the databind(). If you use the .Visible = false option, then during RowDataBound the column is still there .

Upvotes: 0

mustafabar
mustafabar

Reputation: 2359

or try

  dataGridView1.Columns[index].Visible = false; // the index of the column to be hidden

Upvotes: 2

Max
Max

Reputation: 2571

Before exporting the data, do something like:

myGridView.columns.RemoveAt(index);    //Index is the index of the column you want to remove
myGridView.Databind();

Upvotes: 10

Related Questions