简体   繁体   English

C#Winforms带有DataGridView的可视继承问题

[英]C# Winforms visual inheritance problem with DataGridView

From here I have created a BaseForm , then set all its BaseForm.Designer.cs private members to protected . 这里,我创建了一个BaseForm ,然后将其所有BaseForm.Designer.cs private成员设置为protected Then has had a visually inherited/derived Form . 然后具有可视的继承/派生Form

Now I am able to re-size or modify all the controls in the derived Form in design-time except the DataGridView . 现在,我可以在设计时调整大小或修改派生Form中除DataGridView之外的所有DataGridView I am finding the DataGridView as locked in the derived Form , even though it is not locked in the BaseForm . 我发现DataGridView锁定在派生的Form ,即使它未锁定在BaseForm中也是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 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 您可以创建一个用户控件类并从DataGridView类派生

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

It seems an issue with some .NET controls. 某些.NET控件似乎有问题。 There's a good writing here: 这里有个不错的文章:

DataGridView locked on a inherited UserControl DataGridView锁定在继承的UserControl上

I guess that VS designer locks controls that came from base classes. 我猜想VS设计器会锁定来自基类的控件。 Because you have same initialization code you would change properties of grid inside of base class, that affects all other derived forms. 因为您具有相同的初始化代码,所以您将在基类内部更改grid的属性,这会影响所有其他派生形式。

If you want to change properties of your grid, I would recommend to have separate grid for child form, since it should behave differently. 如果要更改网格的属性,我建议为子表单使用单独的网格,因为它的行为应有所不同。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM