1

I keep having the columns from some of my DataGridViews disappearing randomly in the designer, and of course then nothing shows up when I run the application either. Currently I can't even set the datasource to None and then back to my binding source (which has always worked in the past), so I guess I need to create a new DataGridView and rebind the datasource to it. The problem is I add several listeners, set column widths, etc. and I can't keep track of everything I do to every table (and I shouldn't have to!). And I am tired of redoing the same thing over and over again.

I have done a little searching and found that others have this problem and it may be a bug in Visual Studio (I am using Visual Studio Express 2013). So my question: Am I doing something to cause this and can I prevent it from happening again?

Edit I have determined the cause, but still not the solution. It happens when I change the DataTable behind the DataGridView by, for instance, adding or removing a column in the DataTable, and then add or remove that column to the DataGridView. Once I do that, all of the columns disappear from the Designer, including any listener code, etc. I added. I would really appreciate some help on this since it happens to me all the time since I am working on a project with changing needs and it is impossible to have the DataTables be static at this point. And it is really hard to remember the column widths, what listeners/tooltips/etc. I added to which columns, etc. This totally seems like it is a bug in the Designer.

1
  • I edited the post with more specific information that might help determine the problem and, more importantly, the solution.
    – ferzle
    Commented Mar 26, 2014 at 19:47

8 Answers 8

1

I have recently faced the a similar problem with a Datagridview bound to a DataSource. When I was trying to add a new column to the Datagridview, all columns would disappear on pressing OK button in the column editor window.

Cause: In my case it turned out that the new column I was trying to add was named 'override' in the database which is a reserved word in C#. Designer was trying to add the column with its existing name which of course was messing things up.

Solution: Just change the Name property of the column in the column editor window before saving changes to your Datagridview. No need to change anything in your database or anywhere else.

0

I also faced similar issue. Make the changes in designer.cs file. You will find all your columns in the designer.cs file. You can still add new columns using add column.

0

I just had this problem with my project.

Problem Description: I was adding a new databound column to my DataGrid. After pressing OK in the Edit Columns window, all columns disappeared.

Solution: Sadly you will loss your DataGrid columns configuration. Save the project and Reload. Columns will appear again (if not, set the DataSource again).

Side Effects: The worst part of this bug is that all components that were previously associated to your DataGrid will still exist in the project and I was not able to delete them using the designer or the Solution Explorer.

Project Cleanup: I had to clean up my project following this procedure:

  • Go to the DataGridColumn in Solution Explorer. It will show up in your project in the .Designer.cs file.
  • Delete or comment the line of the file.
  • Errors will appear in your error list.
  • Delete or comment the lines reported in the errors (located on InitializeComponent() method).

Caveat: I did the recommended changes and had no problems with my project. However always make a backup of your project before doing manual corrections like the ones I described.

Good luck and happy coding.

0

Adding from Add Column not from edit columns will solve the problem

May be its a bug. But it worked for me to add column from the Add Column option as shown in pic and not from Edit Columns option.

0

I'm using VS 2013 and facing the same issue. I open the design form, edit the datagridview's column and then press OK but after that all column in my datagridview is gone.

I fix this by renaming all the column started with _ (underscore) and then press OK and everything just worked fine. Maybe it's a VS bug or my column name contains a reserved word.

take a look at my screenshot

0

I had the same problem with a column whose name ended with ?. Using an alias without the ? solved the problem. incidentally if, after the columns disappear, you close and open the form again in the IDE, you find that the columns are still there but all your laboriously applied formatting has disappeared. Thank heavens for source code control.

0

I had the same problem in VS 2015 with my columns disappearing from dataGridView. The cause, in my case, turned out to be that I had a column with the same name as a string variable from Form1. The solution for me was to rename the string variable and all of its references. After that, I was able to edit the "Columns" property without any columns disappearing. Hope this is helpful anyone still facing this issue.

0

Use Add Column instead of Edit Columns.

enter image description here

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.