Peter Bromberg [C# MVP] wrote:
Sample working code (Nortwind, "orders"):
SqlConnection cn = new
SqlConnection(@"server=(local);database=northwind; uid=sa;pwd=;");
SqlCommand cmd = new SqlCommand("select * From orders");
cmd.Connection =cn;
SqlDataAdapter ad = new SqlDataAdapter(cmd);
DataSet ds = new DataSet();
ad.Fill(ds);
this.dataGridView1.DataSource = ds.Tables[0];
this.dataGridView1.Columns[0].Visible = false; //OrderID
this.dataGridView1.Columns[1].Visible = false; //CustomerId
--Peter
I have similar problem.
I am also using mdichildren with datagridview.
And I want to hide first column hidden on each datagridview.
If child has no tab pages (datagridview inside tab page)
datagridview remembers that it has to hide column.
If child has tab pages I have to manully set it again
after Form_Load.
And on one form I have three datagridview's and I'm
unable to hide columns on all three because third
datagridview is dependant on one of previous so
setting it after Form_Load doesn't work.
It works only if I set it after setting data,
which is way after Form_Load.
Also, I noticed that problematic columns are only
ones that contains primary key.
I have plenty of hidden columns that contains data,
but are not part of the primary key in the table which
is set as datasource for datagridview.
This behaviour seems like a bug to me.