Data grid columns still showing up

A

Angel Fernendez

I am using a run-time connection to populate a datagrid and when I try to
hide my columns it does not work. If I set the column index higher I get an
error.

here is the code

cn.Open();

SqlCommand cmd = new SqlCommand(sSQL,cn);

DataTable dt = new DataTable();

SqlDataAdapter da = new SqlDataAdapter(cmd);

da.Fill(dt);

DataGrid1.DataSource = dt;

DataGrid1.DataBind();

this.DataGrid1.Columns[1].Visible = false;

does anyone have any suggestions?
Please help!!

Thanks!!
 
S

source

According to MSDN, you can only manipulate (specially using the visible
property) only the explicitly declared columns. If you have
'AutoGenerateColumns' = 'True' for your datagrid then you wont be able to
use the Columns collection for the datagrid.
Even I am trying to hide a column which is not explicitly declared.

Anybody who knows how to hide a column which is not explicitly declared let
me know.
 
G

Greg Baugher

I have a column in a datagrid that I don't want displayed, but still need
access to the data. I changed the column width in the DataGridTableStyle.

According to MSDN, you can only manipulate (specially using the visible
property) only the explicitly declared columns. If you have
'AutoGenerateColumns' = 'True' for your datagrid then you wont be able to
use the Columns collection for the datagrid.
Even I am trying to hide a column which is not explicitly declared.

Anybody who knows how to hide a column which is not explicitly declared let
me know.

Angel Fernendez said:
I am using a run-time connection to populate a datagrid and when I try to
hide my columns it does not work. If I set the column index higher I get an
error.

here is the code

cn.Open();

SqlCommand cmd = new SqlCommand(sSQL,cn);

DataTable dt = new DataTable();

SqlDataAdapter da = new SqlDataAdapter(cmd);

da.Fill(dt);

DataGrid1.DataSource = dt;

DataGrid1.DataBind();

this.DataGrid1.Columns[1].Visible = false;

does anyone have any suggestions?
Please help!!

Thanks!!
 

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,537
Members
45,022
Latest member
MaybelleMa

Latest Threads

Top