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 {
}
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With