datagridview columns appear to be removed from design view, after changing a column name in design view

bigteks

Member
Joined
Nov 7, 2019
Messages
7
Looking around in Google it looks like this is a known issue, sadly I did not create a backup before I made the change.

I have an unbound datagridview in my form that I update programmatically. I changed one of the column names in design view and now it is a grey blank in the design view in Visual Studio. The columns still seem to be there in the Form1.Designer.cs file but if I right click and try to edit columns there is nothing there. Also if I build it, the same thing - the datagridview comes out blank.

Is there any known way to revert to the original column layout and get the columns back? I can't seem to find a way back from here, since I can't edit the columns in design view now. I also can't add them back because it apparently still knows about the columns and refuses to allow me to add them again.

I can recreate it but it will be a lot of work.

Thanks
 
I think I made a noob mistake by naming a column "Size" which is also a property name for most controls. So when I thought better of it later and tried to rename it, I am wondering if the process of VS trying to rename it caused some inadvertent havoc. It was working fine before I went and tried to rename it.
 
OK it turns out I did have a backup, backblaze to the rescue! I was able to recover a version of the Form1.Designer.cs file from right before I made the bad change, load it and see that it worked, and then unload the project and manually edit the file to change the column name. This worked.

So next time I decide to change any names of control elements after already writing some code around them, I guess I will be a little more cautious. The VS designer apparently has a non-zero risk of getting confused, and might wedge my control if I try to make that kind of change from within Designer.
 
Source control is your friend. Use it. Glad you had a back up as an alternative.

Personally, when I used to do WinForms, I gave up on using the designer and only hand code my forms.
 
DGV is a Trojan control, unreliable at best and always generates some problem for me. It's the only control from Winforms which I won't touch with a stick. In fact I nearly never reply to DGV related topics either. As for the Winforms designer, the designer itself in Winforms has burned me so many times, I just prefer to write out my own code by hand to. Besides, we should all be using WPF nowadays anyways. We wouldn't have half the grief if we did. I guess some of us are still suckers for a headache.
 
I'm sorry you had such a poor experience with the DataGridView. The DataGridView is actually one of the very few brand new controls written for WinForms that is not a simple wrapper around an existing Win32 API control. The WinForms team decided not to invest more into the flakey VB DataGrid.OCX. The opted to start from scratch and designed and wrote from the ground up to be a first class example of custom C# control with many options to extend the control. The downside of a brand new code base is that it is not as road tested as the other WinForms controls which were just simple wrappers. The wrappers had years of testing going into them because of their existence is prior versions Windows, and all the wrappers had to do was hold on to the window handles and pass along messages. The new DGV code had to depend on the ingenuity and thoroughness of the test team, and hope that there were enough early adopters withi the company who would use the DGV instead of using the older DataGrid, or the ListView. I know that as an early adopter, I had opened several bugs and exchanged lots of email with the developers as I learned how to use the control while the control documentation was still in progress.
 
I'm sorry you had such a poor experience with the DataGridView
I'm not. I've never liked that control and I've always done well without it. And it's not as if there aren't other alternatives. Well I suppose that depends on the project, but a well. We all have our opinions, and I will stick with mine.
 
Back
Top Bottom