Why is DataGridView.AutogenerateColumns not exposed in designer

  • Thread starter Thread starter Crazy Cat
  • Start date Start date
C

Crazy Cat

Does anyone know why this is not exposed in the designer?

Is it just me or is this a really stupid oversight?

I turn it on in code, but that doesn't prevent the designer from every
once in a while autogenerating columns on my datagridview. I can't
seem to predict when this'll happen -- for example, I've got my
datagridview's datasource set to a bindingsource -- I clear out the
unnecessary colums in the datagridview and start the application. All
is fine. However, on subsequent restarts, sometime I'll see that
columns have been autogenerated in the designer, even though in the
particular edit session, I never changed the datasource, or any
aspects of the bindingsource.

How to stop this -- it is ANNOYING!

Thanks,
 
Does anyone know why this is not exposed in the designer?

Is it just me or is this a really stupid oversight?

I turn it on in code, but that doesn't prevent the designer from every
once in a while autogenerating columns on my datagridview. I can't
seem to predict when this'll happen -- for example, I've got my
datagridview's datasource set to a bindingsource -- I clear out the
unnecessary colums in the datagridview and start the application. All
is fine. However, on subsequent restarts, sometime I'll see that
columns have been autogenerated in the designer, even though in the
particular edit session, I never changed the datasource, or any
aspects of the bindingsource.

How to stop this -- it is ANNOYING!

I have run into the same problem. I asked about this here a few
months ago but never received a response.

What I finally did was to create a subclass of DataGridView and set
AutoGenerateColumns = False in the constructor.
 
I have run into the same problem. I asked about this here a few
months ago but never received a response.

What I finally did was to create a subclass of DataGridView and set
AutoGenerateColumns = False in the constructor.

Thanks for your response Jack.

I tried this and yet it is still autogenerating the columns. It must
be something I'm doing.

I looked at my code and the only thing I can put it down to is that I
dynamically set the datasource
in the code, but I set autogeneratecolumns to false in the constructor
of the derived class and for
good measure in the grid. In design view I deleted the extraneous
columns, started the application
and all was good. As soon as I stopped debugging I notice that
magically the columns have been regenerated
in design mode.
 
Thanks for your response Jack.

I tried this and yet it is still autogenerating the columns. It must
be something I'm doing.

I looked at my code and the only thing I can put it down to is that I
dynamically set the datasource
in the code, but I set autogeneratecolumns to false in the constructor
of the derived class and for
good measure in the grid. In design view I deleted the extraneous
columns, started the application
and all was good. As soon as I stopped debugging I notice that
magically the columns have been regenerated
in design mode.

OK, this time I'm pretty sure it's nothing I'm doing. In design mode I
delete the extraneous columns. When I close the form and reopen it in
the designer the columns have been autogenerated. This is only
happening on one datagrid in my application.

WHAT THE HELL?

Sign me,

FRUSTRATED
 
OK, this time I'm pretty sure it's nothing I'm doing. In design mode I
delete the extraneous columns. When I close the form and reopen it in
the designer the columns have been autogenerated. This is only
happening on one datagrid in my application.

WHAT THE HELL?

Sign me,

FRUSTRATED

OK, I found the solution --

Do not set DataSource and DataMember at design time -- set them at
runtime and all is fine.

Actually you might want to set them at design time to get the bindings
for your columns, but after setting the bindings CLEAR OUT THE
Datasource and Datamember properties and set them at runtime.
 
When we use the DGV bindingsource as the datasource for another bindingsource; then "not setting the datasource" at design time does not seem to be an option.

The best solution would be simply for the VS Designer to not autogenerate columns when this property is set to false. That seems simple to me. What don't I know?





Crazy Cat wrote:

Re: Why is DataGridView.AutogenerateColumns not exposed in designer
06-Feb-08


OK, I found the solution -

Do not set DataSource and DataMember at design time -- set them a
runtime and all is fine

Actually you might want to set them at design time to get the binding
for your columns, but after setting the bindings CLEAR OUT TH
Datasource and Datamember properties and set them at runtime.

Previous Posts In This Thread:

Re: Why is DataGridView.AutogenerateColumns not exposed in designer
On Wed, 30 Jan 2008 08:37:59 -0800 (PST), Crazy Ca

I have run into the same problem. I asked about this here a fe
months ago but never received a response

What I finally did was to create a subclass of DataGridView and se
AutoGenerateColumns = False in the constructor.

Why is DataGridView.AutogenerateColumns not exposed in designer
Does anyone know why this is not exposed in the designer

Is it just me or is this a really stupid oversight

I turn it on in code, but that doesn't prevent the designer from ever
once in a while autogenerating columns on my datagridview. I can'
seem to predict when this'll happen -- for example, I've got m
datagridview's datasource set to a bindingsource -- I clear out th
unnecessary colums in the datagridview and start the application. Al
is fine. However, on subsequent restarts, sometime I'll see tha
columns have been autogenerated in the designer, even though in th
particular edit session, I never changed the datasource, or an
aspects of the bindingsource

How to stop this -- it is ANNOYING

Thanks,

Re: Why is DataGridView.AutogenerateColumns not exposed in designer

Thanks for your response Jack

I tried this and yet it is still autogenerating the columns. It mus
be something I'm doing

I looked at my code and the only thing I can put it down to is that
dynamically set the datasourc
in the code, but I set autogeneratecolumns to false in the constructo
of the derived class and fo
good measure in the grid. In design view I deleted the extraneou
columns, started the applicatio
and all was good. As soon as I stopped debugging I notice tha
magically the columns have been regenerate
in design mode.

Re: Why is DataGridView.AutogenerateColumns not exposed in designer

OK, this time I'm pretty sure it's nothing I'm doing. In design mode
delete the extraneous columns. When I close the form and reopen it i
the designer the columns have been autogenerated. This is onl
happening on one datagrid in my application

WHAT THE HELL

Sign me

FRUSTRATED

Re: Why is DataGridView.AutogenerateColumns not exposed in designer

OK, I found the solution -

Do not set DataSource and DataMember at design time -- set them a
runtime and all is fine

Actually you might want to set them at design time to get the binding
for your columns, but after setting the bindings CLEAR OUT TH
Datasource and Datamember properties and set them at runtime.

How to fix the AutoGenerateColumns
I was also being driven crazy by this problem of reappearing columns in the designer even though I had sub classed the DataGridView control and set base.AutoGenerateColumns = false in the constructor.

After analysing ones that seemed to be OK vs ones that were having the problem, I found the corruption to be in the resx file for the datagridview. At the bottom of the file (open with an xml editor), there will be a number of <metadata > elements. Keep the one for your binding source and delete all the ones for the columns.

Now regenerate your solution and then try re-opening your designer. If you are as lucky as me, then your problem should have disappeared.

Good Luck.


Submitted via EggHeadCafe - Software Developer Portal of Choice
An Xml-Driven, Self-Caching ASCX MenuStrip Control
http://www.eggheadcafe.com/tutorial...9355-f85da3698fbc/an-xmldriven-selfcachi.aspx
 
Back
Top