Click here to Skip to main content
15,885,278 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hi.

I have made a class based on DataGridView. I made all my general design changes in that class, using VS designer, and I put that DGV on every form. But now, if I make any changes on my DGV in my class those changes are not propagating to all my forms, because all my initial settings are already stored in form.Designer.cs files.
What should I do to automatically propagate any of the changes in that MyDGV.cs to al my forms which contains that dgv? Rebuilding solution does not do that!

Thanks!

What I have tried:

Rebuilding solution!
I don't know what to do, but only deleting any data about styling dgv in forms designer file and rebuild solution.
Posted
Updated 11-Mar-20 22:20pm

You don't have much choice but to recompile the assembly holding the control, and delete styling data already assigned. The designer is using the *.Designer.cs file to serialize controls' settings; when you change the behaviour/styling of your custom control, the designer does not compare old settings to new ones, it just keeps the settings it had serialized.

Ideally, you should take care of implementing the control once and for all; only when this is done you should begin to use it on your forms. If you keep going back and forth from your control's implementation to its usages, this will quickly become a real nightmare (especially if the control is used in many places).
 
Share this answer
 
Comments
MVSoftVM 12-Mar-20 6:22am    
Maybe I have to make those custom properties of my dgv as public get-set properties with a default value and to be read from a settings file when form loads. I think this is the approach I have to follow.
phil.o 12-Mar-20 6:30am    
Ideally, if you want those custom properties to be shown on the property grid, they should already be public get-set. Giving them a default value will only be reflected when you create a new (design-time) instance of the control; existing instances will not be updated on change of the default value.
Reading from a settings file is always possible, but 1) it may conflict with the .Designer.cs file (whose purpose is rpecisely to serialize specific settings of the control) 2) it will not solve your issue, as the settings will just be read from somewhere else.
As I told, try to focus on developping your control first, and only start to use it when this first stage is done.
If your Form instances of your Control override your Control default values, then they will always be used in preference to any new defaults your control adds - and it really shouldn't be any other way, if you think about it!

If I create a Control with a Red background, and in my form I change that to Blue, then I want that background to remain Blue even if I later change the Control to use a Yellow background - any other behavior would probably constitute a "breaking change" in that it doesn't result in the same user experience as it did without any changes being made in my form code.

If that isn't what is happening here, then you need to explain in a lot more detail exactly what the problem is, as we cannot see your screen, access your HDD, or read your mind - we have no idea what your code looks like!
 
Share this answer
 
Comments
MVSoftVM 12-Mar-20 6:11am    
Hi @OriginalGriff. I don't think it's about reading my mind or whatever, it's written in my question: [quote][i]I made all my general design changes in that class, using VS designer, and I put that DGV on every form[/i][/quote]. Which means that after I made my class and made a design to my grid (selectionbackcolor, selectionforecolor, and so on) I put it on my forms. The problem is Designer will copy that information to my form Designer.cs file, which I don't think it is normal, as long I did not take any local modification in that form to my dgv.
So, my tough was, if I make some styling in a cs file those styling properties will be read from my custom file till I came an modify locally. But this is not happening, which in my opinion is something like a little/big bug. I don't know, it is a tough...

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900