473,390 Members | 1,300 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,390 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 22074
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: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

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.