C# Winforms DataGridView 的视觉继承问题
来自此处我创建了一个 BaseForm
,然后将其所有 BaseForm.Designer.cs
private
成员设置为 protected
。然后就有了一个视觉上继承/派生的Form
。
现在,我可以在设计时调整派生 Form
中除 DataGridView
之外的所有控件的大小或修改。我发现 DataGridView
在派生的 Form
中被锁定,即使它没有在 BaseForm
中锁定。
可能是什么原因?我应该再次寻找/检查什么?
我有一个像这样的基本表单:
我已经派生了一个像这样的表单:
From here I have created a BaseForm
, then set all its BaseForm.Designer.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:
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
这是一个已知问题..
https://connect.microsoft.com/VisualStudio/feedback/details/284335/designer-prevents-access-to-protected-datagridview-control-in-inherited-form
您可以创建用户控件类并派生自 DataGridView 类
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
我猜想 VS 设计器会锁定来自基类的控件。因为您具有相同的初始化代码,所以您将更改基类内部网格的属性,这会影响所有其他派生形式。
如果您想更改网格的属性,我建议为子表单使用单独的网格,因为它的行为应该有所不同。
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.
这似乎是某些 .NET 控件的问题。
这里有一篇很好的文章:
DataGridView 锁定在继承的 UserControl
It seems an issue with some .NET controls.
There's a good writing here:
DataGridView locked on a inherited UserControl