A
A
Alexis178422016-01-16 08:36:33
C++ / C#
Alexis17842, 2016-01-16 08:36:33

How to restore an accidentally deleted control in the designer window in winforms?

Can you please tell me how to restore an accidentally deleted control (datagridview) on the main form in the designer window?
The datagrid code remains, but is it possible to update the image or do I need to create a new grid and paste the old code into it?
IDE - VS 2013 Express, language - c#

Answer the question

In order to leave comments, you need to log in

3 answer(s)
G
GavriKos, 2016-01-16
@GavriKos

The most reliable thing is to roll back to the previous commit in which this control was.

A
Alexey Nemiro, 2016-01-16
@AlekseyNemiro

With Windows Forms , you need to be prepared for all sorts of tricks from Visual Studio .
Even when using version control systems, sometimes you have to tinker with tricks in the form of missing pictures or child elements in some menu or ToolStrip . Many of these cases can be corrected by hand, by manually fixing Designer files , but not always. The more complex the form, the higher the risk that the studio designer will break something; you always have to be ready for it.
1. Since such a question has appeared, then apparently Ctrl + Z will definitely not help. This is the first thing to do.
2. If the form was not saved, then to roll back the changes, it would be possible to simply close it without saving. But then again, this should have been done immediately, if a problem occurred and if the usual rollback ( Ctrl + Z ) did not help.
3. If you do not use a version control system, then you need to regularly make backup copies of the source code. Using version control systems will be more convenient. But even when using version control systems, you should make regular backups, and back up backups.
4. If there is an assembly of the desired state of the program (or approximately this state) and the work on the missing interface was carried out by sweat, without breaks for lunch and sleep, and everything is very difficult and you don’t want to repeat this heroic deed, then you can decompile the previous assembly and pull it out interface description code from it. For example, with dotPeek .
Descriptions of form elements, by default, are in Designer files . For example, the Form1 elements can be found in the Form1.Designer.cs file . Sometimes elements can simply lose references to their parents. The case of accidentally deleting an element and rolling back ( Ctrl + Z ) can just lead to such behavior. Code in the Designer fileusually remains and links can be corrected by hand. As a rule, we are talking about adding lines of code like: this.parentElement.Controls.Add(this.childElement) . The main thing is to understand what has fallen off from what and what needs to be tied to what. If you do not understand, then you can make things worse :-) (don't forget about creating backups). After making changes to the designer code, you should reopen the form designer (ideally, before making changes to *.Designer.cs , it is better to close the form designer (visual form editor).
If the element is completely removed and the restoration from the previous assembly is used, then in the decompiled code you will need to find the form class, and in it the InitializeComponent method . DataGridView _, each column and row (if any) will be separate elements, you need to find and transfer the entire code for describing these elements. As a rule, for each individual element, setting values ​​for properties in the code goes sequentially. Child elements can be scattered, by the names of the elements you can more or less understand what's what (if the standard names of the elements have changed to their own, then there should be no problems with the search).

A
Alexander Ananiev, 2016-01-16
@SaNNy32

If there is a version control system, then as they wrote - roll back to the previous commit.
If not, then only restore the pens.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question