C# Winforms visual inheritance problem with DataGridView
From here I have created a BaseForm
, then set all its BaseForm.Designe开发者_开发技巧r.cs
private
members to protected
. Then has had a visually inherited/derived Form
.
Now I am able to re-size or modify all the controls in the derived Form
in design-time except the DataGridView
. I am finding the DataGridView
as locked in the derived Form
, even though it is not locked in the BaseForm
.
What can be the reason? What should I look/check for again?
I have a base form like this:
And I have derived a form like this:
It is a known problem..
https://connect.microsoft.com/VisualStudio/feedback/details/284335/designer-prevents-access-to-protected-datagridview-control-in-inherited-form
You can create a user control class and derive from DataGridView class
[Designer(typeof(System.Windows.Forms.Design.ControlDesigner))]
public class MyDataGridViewUserControl : DataGridView { }
I guess that VS designer locks controls that came from base classes. Because you have same initialization code you would change properties of grid inside of base class, that affects all other derived forms.
If you want to change properties of your grid, I would recommend to have separate grid for child form, since it should behave differently.
It seems an issue with some .NET controls. There's a good writing here:
DataGridView locked on a inherited UserControl
精彩评论