0

I'm sure you know the problem, as soon as a BindingSource is connected to a DataGridView the DataGridView generates columns for each Property found in the Type of the BindingSource's DataSource and adds that crap to the Form.Designer.cs file.

We only use run time generated columns, the clutter in the designer file is just waste of code, so how can we stop this "feature" of the DataGridView in WinForms?

2
  • Why do you want to do that? If its in the designer file, nobody will ever read it. Do you really have performance problems caused by this?
    – Jens
    Commented Apr 23, 2010 at 13:13
  • Thing is, VS randomly reorders items in the designer file from time to time and merging is really annoying if hundreds of lines only move inside the file. Secondly we use 8 DataGridViews on one Form that each generate around 100 columns automatically, only 3-4 at runtime. Commented Apr 23, 2010 at 13:17

2 Answers 2

1

Tell it to not auto-generate columns. http://msdn.microsoft.com/en-us/library/system.windows.forms.datagridview.autogeneratecolumns.aspx

2
  • Sorry, does not work actually. as soon as the BindingSource gets connected in the designer, the columns are generated and the designer file gets polluted. Commented Apr 23, 2010 at 14:08
  • What is the big deal really? No one looks at the designer file anyway. I think the columns are generated just for the designer. You could always take it off the form and manually add the datagridview to the form.
    – nportelli
    Commented Apr 23, 2010 at 17:45
0

DataGridView.AutoGenerateColumns = false

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.