Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cannot visually change DataGridView in inherited form

I have a WinForms form with a DataGridView on it. The DataGridView is set to protected.

When I inherit that form, it is not possible to change the DataGridView in the Visual Studio designer. If I do the whole thing with a Button, it works as expected.

Is there a way to fix this?

Some (clipped) code (from DatagridForm.Designer.cs):

partial class DatagridForm {
    protected DataGridView dgData;
    protected Button button;
}

and from Inherited.cs:

partial class Inherited : DatagridForm {

}
like image 538
Bart Friederichs Avatar asked Feb 26 '13 12:02

Bart Friederichs


1 Answers

This blog has the solution: just create an inherited user control that points to the right designer stuff:

[Designer(typeof(System.Windows.Forms.Design.ControlDesigner))]
public class ucInheritedDataGridView : DataGridView { }

Works like a charm. Only downside is that you cannot use the .NET Client Profile, because it has no support for System.Forms.Design (you have to add System.Design as a reference). This shouldn't be too much of a problem, because the client profile is deprecated anyway per 4.5.

If you really need the client profile, another work around is to wrap the DataGridView in a Panel, which you can move and resize.

like image 65
Bart Friederichs Avatar answered Sep 19 '22 15:09

Bart Friederichs