不能以可视方式更改的DataGridView在继承的形式 [英] Cannot visually change DataGridView in inherited form
问题描述
我有一个WinForms与 DataGridView的
上形成。在 DataGridView的
设置为保护
。
当我继承的形式,这是不可能更改 DataGridView的
在Visual Studio设计。如果我做一个按钮
,它按预期工作的整个事情。
有没有办法解决这个问题?
有些(剪切)码(从DatagridForm.Designer.cs):
部分类DatagridForm {
保护的DataGridView DGDATA;
保护Button按钮;
}
和来自Inherited.cs:
部分类继承:DatagridForm {
}
这博客有解决方案:只要创建一个指向正确的设计师的东西继承的用户控件:
[设计师( typeof运算(System.Windows.Forms.Design.ControlDesigner))]
公共类ucInheritedDataGridView:DataGridView的{}
工程就像一个魅力。唯一的缺点是你不能使用.NET客户端配置文件,因为它有System.Forms.Design不支持(必须添加 System.Design
作为参考)。这不应该是太大的问题,因为客户端配置文件是过时反正每4.5
如果你真的需要在客户端配置文件,另一个解决办法是在<$ C包住 DataGridView的
$ C>面板,您可以移动和调整。
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.
这篇关于不能以可视方式更改的DataGridView在继承的形式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!