|
-
October 23rd, 2008, 04:24 AM
#1
DataGridView AutogenerateColumns not working in XP
Hi guys,
One of my applications contains a large datagridview, which is updated every 5 seconds to show data. I have set it up with a selection of columns and have databound it programmatically. In the form's constructor I execute this statement:
Code:
grid.AutogenerateColumns = false;
This should prevent the datagridview from showing any other columns than the ones I have defined at design time.
And it does, when the application runs on a Vista machine. As soon as I run it on an XP machine, the datagridview generates the columns anyway.
The datasource is an ArrayList containing custom objects. The objects are of a simple reference type called Customer and they contain the generic properties we all know and love (ID, Name etc.)
I found a solution to this problem. If I put the above statement in the .Designer.cs file, it works on XP. No matter where I put it other than in there, it won't work. It works on Vista either way...
Can someone please explain this behavior? 'Cos I'm thoroughly stumped!
It's not a bug, it's a feature!
-
October 23rd, 2008, 09:23 AM
#2
Re: DataGridView AutogenerateColumns not working in XP
How about using bindingSource control for this?
First you set up all columns with DataPropertyName in datagridview, then set datasource to bindingSource control. After you get data, set it to bindingSource.DataSource. It's done!
The difficulty is that you have no idea how difficult it is.
.Net 3.5/VS 2008
-
October 23rd, 2008, 09:29 AM
#3
Re: DataGridView AutogenerateColumns not working in XP
There should not be any difference in behaviour bases on the operating system.
Are you 100% sure both machines have thew EXACT same version of the .NET framework installed????
TheCPUWizard is a registered trademark, all rights reserved. (If this post was helpful, please RATE it!)
2008, 2009,2010
In theory, there is no difference between theory and practice; in practice there is.
* Join the fight, refuse to respond to posts that contain code outside of [code] ... [/code] tags. See here for instructions 
* How NOT to post a question here
* Of course you read this carefully before you posted
* Need homework help? Read this first
-
October 24th, 2008, 01:33 AM
#4
Re: DataGridView AutogenerateColumns not working in XP
Yup, I updated both of them to 3.5 SP1 in an attempt to solve the problem. This had no effect...
I'm just a host of strange problems at the moment 
EDIT: To answer the bindingsource suggestion, this is how I do it at the moment:
Constructor:
Code:
grid.AutoGenerateColumns = false;
Method called from Form_Load()
Code:
Customers = driver.GetAllCustomers();
gridCustomers.DataSource = Customers;
I'm not sure if the suggested method of databinding would change anything?
Last edited by foamy; October 24th, 2008 at 01:38 AM.
It's not a bug, it's a feature!
-
October 24th, 2008, 09:12 AM
#5
Re: DataGridView AutogenerateColumns not working in XP
It's different. Don't set AutoGenerateColumns to false. bindingSource control will manage all columns. If there is no difference whether you use bindingSource or not, what is this control for? It makes display in datagridview very flexible, you can show whatever you want.
The difficulty is that you have no idea how difficult it is.
.Net 3.5/VS 2008
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|