Can't hide column in datagrid

E

enak

I populate a datagrid by setting the datasource to a
datatable. I then, bind them. After that I try to hide the
last column but am not able to. I get an error message.

Here is my code:

Me.dgReport.DataSource = ds.Tables("tFirst")
Me.dgReport.DataBind()
Me.dgReport.Columns(7).Visible = False

Here is the error that I get:

System.ArgumentOutOfRangeException: Index was out of
range. Must be non-negative and less than the size of the
collection. Parameter name: index


If I take the last line of code out then the page
displayes as expected except for the last column. I tried
to hide column 3 but got the same result.

After the Bind command I looked at the Columns.Count
property and it is 0. Why is this happening and how do I
fix it?

Thanks
enak
 
S

Sunil TG

You should write
Me.dgReport.Tables(0).Columns(7).Visible = False
Then it will work fine.

Sunil TG
 

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

Forum statistics

Threads
473,764
Messages
2,569,564
Members
45,041
Latest member
RomeoFarnh

Latest Threads

Top