2013-02-26 89 views
4

我有一个WinForms表单,其上有一个DataGridViewDataGridView设置为protected不能在继承形式下直观地更改DataGridView

当我继承该表单时,不可能在Visual Studio设计器中更改DataGridView。如果我用Button完成整件事情,它就会按预期工作。

有没有办法解决这个问题?

一些(限幅)代码(来自DatagridForm.Designer.cs):

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

和从Inherited.cs:

partial class Inherited : DatagridForm { 

} 
+0

作为例子,你能给我们一些代码吗? – christopher 2013-02-26 12:37:28

+0

添加了一些代码。我可以在“Inherited”的设计器中轻松移动按钮。即使'Locked'设置为'False',DataGridView也被锁定。 – 2013-02-26 12:42:03

+0

这似乎是旧的:http://stackoverflow.com/questions/207504/datagridview-locked-on-a-inherited-usercontrol – 2013-02-26 12:52:30

回答

7

blog具有溶液:只是创建一个继承的用户控制指向正确的设计师的东西:

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

工程就像一个魅力。唯一的缺点是你不能使用.NET客户端配置文件,因为它不支持System.Forms.Design(你必须添加System.Design作为参考)。这应该不是太大的问题,因为客户端配置文件是deprecated anyway per 4.5

如果您真的需要客户端配置文件,另一个解决方法是将DataGridView包装在Panel中,您可以移动和调整大小。