hide column in data grid

B

BK Kim

Hello.

I just populated my datagrid but I need to hide one of the column.

Since I need this column's data, I cannot drop that column from my store
procedure.

Is there a way I can make it invisible?

I tried

dataGrid1.Columns[1].visible = false;

but didn't work and complained that I am out of index range.

Any one know how to solve it?

Thanx in advance
 
C

Craig Burkett

And you couldn't post it a 101st time? :)

Seriousely, what is the solution because I am having a similar problem. The
only difference is that I have a databound grid with two fixed columns and
am wanting the rest of them to be auto generated. The problem is that the
two fixed columns get duplicated in the grid because I can't keep them from
being auto-generated.

Thanks,
Craig

Alvin Bruney said:
i've posted a solution to the hundred other places you posted this question
BK Kim said:
Hello.

I just populated my datagrid but I need to hide one of the column.

Since I need this column's data, I cannot drop that column from my store
procedure.

Is there a way I can make it invisible?

I tried

dataGrid1.Columns[1].visible = false;

but didn't work and complained that I am out of index range.

Any one know how to solve it?

Thanx in advance
 
A

Alvin Bruney

101 and counting
in your itemdatabound event do this:
e.item.cells[9].visible = false;
this will hide autogenerated columns. bound columns are part of the column
collection so if you have 2 bound columns your index will be 0 and 1 and you
would hide them the same way you were trying to hide them before. it can't
work for autogenerated columns because they aren't part of the columns
collection. ex if you have 2 bound columns and 4 autogenerated columns, you
only have index 0 and 1 which is why you kept getting and index out of range
when you tried to hide column 4. if you use the itemdatabound then you can
hide the 4 autogenerated columns but not the 2 bound columns for the same
reason

hope this helps

Craig Burkett said:
And you couldn't post it a 101st time? :)

Seriousely, what is the solution because I am having a similar problem. The
only difference is that I have a databound grid with two fixed columns and
am wanting the rest of them to be auto generated. The problem is that the
two fixed columns get duplicated in the grid because I can't keep them from
being auto-generated.

Thanks,
Craig

Alvin Bruney said:
i've posted a solution to the hundred other places you posted this question
BK Kim said:
Hello.

I just populated my datagrid but I need to hide one of the column.

Since I need this column's data, I cannot drop that column from my store
procedure.

Is there a way I can make it invisible?

I tried

dataGrid1.Columns[1].visible = false;

but didn't work and complained that I am out of index range.

Any one know how to solve it?

Thanx in advance
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,007
Latest member
obedient dusk

Latest Threads

Top