473,322 Members | 1,911 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,322 software developers and data experts.

Unable to hide columns in datagridview

I have the following:

this.dataGridViewBill.DataSource = tblResult;

//hide the following columns
this.dataGridViewBill.Columns[8].Visible = false; //email
this.dataGridViewBill.Columns[9].Visible = false; //mobiltelefon

When I run the programm, the columns are still displayed.
I am developing with Visual C#2005 Express Edition Beta.

Can any give me some tipps of what I'm doing wrong.

Thanks in anticipation

Jan 17 '06 #1
4 22063
You need to do this after the grid is databound for it to work properly.
Peter
--
Co-founder, Eggheadcafe.com developer portal:
http://www.eggheadcafe.com
UnBlog:
http://petesbloggerama.blogspot.com


"Stropher" wrote:
I have the following:

this.dataGridViewBill.DataSource = tblResult;

//hide the following columns
this.dataGridViewBill.Columns[8].Visible = false; //email
this.dataGridViewBill.Columns[9].Visible = false; //mobiltelefon

When I run the programm, the columns are still displayed.
I am developing with Visual C#2005 Express Edition Beta.

Can any give me some tipps of what I'm doing wrong.

Thanks in anticipation

Jan 17 '06 #2
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
--
Co-founder, Eggheadcafe.com developer portal:
http://www.eggheadcafe.com
UnBlog:
http://petesbloggerama.blogspot.com


"Stropher" wrote:
I have the following:

this.dataGridViewBill.DataSource = tblResult;

//hide the following columns
this.dataGridViewBill.Columns[8].Visible = false; //email
this.dataGridViewBill.Columns[9].Visible = false; //mobiltelefon

When I run the programm, the columns are still displayed.
I am developing with Visual C#2005 Express Edition Beta.

Can any give me some tipps of what I'm doing wrong.

Thanks in anticipation

Jan 17 '06 #3
Thanks Peter for your quick reply.
I figured out, that the problem had to do with MDIParent.
What I did was to make sure that the hiding has to take place
immediately after displaying the form containing the datagridview.
Example: Assuming that the control->datagridview is in Form1
In class MDIParent ..._Load(...)
Form1 f1 = new Form1();
f1.MdiParent = this;
f1.show();
f1.datagridview1.Columns[0].Visible = false;

where datagridview1.Datasource = tableResult; //is done in Form1

With this, I was able to hide the columns in question successfully.

Thanks and regards,
Stropher

Jan 18 '06 #4
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.
Jan 19 '06 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Midiman69 | last post by:
Can any one help with a problem I have with a tab control form I have a form with a two page tab control - page 1 being the main form. I have a data sheet view subform on page 2.(linked by...
0
by: Benny Raymond | last post by:
I just wanted to figure out a way to have a list view work like the microsoft explorer list view, so I could show/hide columns with a right click - anyone know the best way of going about this? ...
1
by: J Gao | last post by:
Hi All, I am using Data binding with DataGrid. I need to hide column in the grid using DataGrid1.Columns(1).Visible = False But I get the following error message Description: An unhandled...
5
by: J | last post by:
Ok, they have changed a lot of stuff in VB.net. How in the world do you hide a column on the Datagrid? -- Jason
1
by: Simon | last post by:
Dear reader, In a form with the property "Default view" as DataSheet I like to hide some fields in the datasheet view. It is possible to manage this with the command Format>>Unhide...
1
by: MrNobody | last post by:
what's the trick in showing/hiding columns in ListView's Details view mode? I can change a columns width to 0 and it effectively makes it disappear but then you can actually resize the column to...
2
by: Phil Sandler | last post by:
Quick question: Is it possible to use autogeneratecolumns = true and still hide specific columns based on the column name in the datasource? Failing that, can it be done by column index? ...
3
by: =?Utf-8?B?U3RldmVU?= | last post by:
Is it possible with VS 2005 to hide a row within a datagridview based upon the "true/false" status of another boolean property within the datagridview? -- ----------- Thanks, Steve
0
Frinavale
by: Frinavale | last post by:
This code snippet is just a little bit of fun. It demonstrates how you use JavaScript and CSS to show or hide columns in a table depending on whether or not a checkbox corresponding with the...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.