我有一段代码,如下所示:我使用的是Microsoft Visual c# Express Edition。我的问题是,我不能添加列的DataGridView在设计时,这是另一个类的成员。下面是我的代码:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace ClassLibrary1
{
public class Class1 : Panel
{
DataGridView mView;
public Class1()
{
mView = new DataGridView();
this.Controls.Add(mView);
}
public DataGridView View
{
get { return mView; }
set { mView = value; }
}
}
}
当我点击三个虚线按钮在属性窗口添加新列时,我得到了系统。设计时的NullException。因为我的名声,我不能发布截图。
谢谢你的帮助!
我只是更深入地研究了一下你的问题。不幸的是,我无法重现所描述的物质。在对usercontrols中的DataGridView进行了一些研究之后,我翻阅了下面的文章。
似乎有没有可视支持为继承的DataGridView -和-不为userControls使用DataGridView,太。你也可以看看这篇文章
我尝试使用以下继承的DataGridView类-但都不起作用。我很抱歉没有一个合适的解决方案,但我希望这可能对你有用。
/// tried this attribute - did not work
/// [Designer(typeof (System.Windows.Forms.Design.ControlDesigner))]
/// this did not work either
[Editor("System.Windows.Forms.Design.DataGridViewComponentEditor, System.Design, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a", typeof(ComponentEditor))]
[Designer("System.Windows.Forms.Design.DataGridViewDesigner, System.Design, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a")]
public class ucInheritedDataGridView : DataGridView { }