4

I have a datagridview that is linked to a three columns in the database, and it's only displaying them (no editing). When I run the program in debug, and exit, when I return to the form in Visual Studio, it has my three columns, plus all the columns in the table it's linked to. If I don't remove these, the next time I run the program, they show up on the form. If I remove them, I have to do it every time I run the program.

Any ideas on how to fix this?

2
  • How is it linked to the database? Are you using a strongly-typed dataset and a BindingSource, or some other method?
    – lc.
    Commented Feb 27, 2009 at 16:39
  • It is being bound with a strongly typed dataset and binding source
    – Malfist
    Commented Feb 27, 2009 at 16:44

3 Answers 3

4

According to this there is a bug in Visual Studio that requires you to set the binding source to none/null before changing it (It seems to have been around since 2005). I removed all the columns, set binding source to none, then reset the binding source to what I wanted and edited the columns. It is working now.

2
4

Is AutoGenerateColumns set to True ?

You should set it to False if you want to prevent the DGV from creating columns (in addition to those you created manually) from the datasource.

Edit: To clarify, this admittedly weird behaviour could result if the property is not set to False in design mode itself. I'm thinking of the corner case in which you set it to False at runtime. I would also take a look at the designer file (you might have to click the "show all files" option to view it) and see what it contains pertaining to the DGV. Might be a problem there.

Alternatively, have you tried deleting the control itself and creating a new DGV with the same bindings?

2
  • AutoGeneratedColumns is set to false.
    – Malfist
    Commented Feb 27, 2009 at 16:36
  • The designer file sets the AutoGeneratedColumns to false, and only shows the columns I manually added. Not the ones that get added after running the program.
    – Malfist
    Commented Feb 27, 2009 at 16:48
3

After lots of digging around, this solution finally solved it for me:

It looks like the compiler is corrupting the .resx file (which contains the form's layout information, including the column settings), which means next time you load the designer it recreates all the columns from the datasource.

The fix appears to be as follows:

Do a "show all files" and then view the .resx file associated with the form and change the columns that are giving you the aberrant behavior... look for the column name followed by ".UserAddedColumn" Entry, and set it to False. In my case I actually went so far as to altogether delete the entries that say "[columnName].UserAddedColumn".

0

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.