我正在为自己的MyDataGridView控件开发自己的列。
using System;
using System.ComponentModel;
using System.Drawing;
using System.Text;
namespace WindowsFormsApplication1
{
public class MyDataGridView : System.Windows.Forms.DataGridView
{
}
public class MyDataGridViewComboBoxColumn : System.Windows.Forms.DataGridViewComboBoxColumn
{
}
public class MyDataGridViewTextBoxColumn : System.Windows.Forms.DataGridViewTextBoxColumn
{
}
public class MyDataGridViewCheckBoxColumn : System.Windows.Forms.DataGridViewCheckBoxColumn
{
}
public class MyDataGridViewButtonColumn : System.Windows.Forms.DataGridViewButtonColumn
{
}
public class MyDataGridViewLinkColumn : System.Windows.Forms.DataGridViewLinkColumn
{
}
public class MyDataGridViewImageColumn : System.Windows.Forms.DataGridViewImageColumn
{
}
}
我想知道是否可以在设计时隐藏编辑列对话框窗体中的System.Windows.Forms中定义的标准DataGridView列,以便我只能使用自己的列。< / p>
答案 0 :(得分:1)
我出来了。
using System;
using System.Collections;
using System.ComponentModel;
using System.ComponentModel.Design;
using System.Windows.Forms;
namespace WindowsFormsApplication1
{
public class MyDataGridView : System.Windows.Forms.DataGridView
{
public override ISite Site
{
get
{
return base.Site;
}
set
{
base.Site = value;
if (Site != null)
{
IDesignerHost host = (IDesignerHost)Site.GetService(typeof(IDesignerHost));
if (host != null)
{
host.RemoveService(typeof(ITypeDiscoveryService));
host.AddService(typeof(ITypeDiscoveryService), new TypeDiscoveryService());
}
}
}
}
static readonly Type[] columnTypes = new Type[]
{
typeof(MyDataGridViewButtonColumn),
typeof(MyDataGridViewCheckBoxColumn),
typeof(MyDataGridViewLinkColumn),
typeof(MyDataGridViewImageColumn),
typeof(MyDataGridViewComboBoxColumn),
typeof(MyDataGridViewTextBoxColumn)
};
class TypeDiscoveryService : ITypeDiscoveryService
{
ICollection ITypeDiscoveryService.GetTypes(Type baseType, bool excludeGlobalTypes)
{
return columnTypes;
}
}
}
[System.Windows.Forms.DataGridViewColumnDesignTimeVisible(true)]
public class MyDataGridViewComboBoxColumn : System.Windows.Forms.DataGridViewComboBoxColumn
{
}
[System.Windows.Forms.DataGridViewColumnDesignTimeVisible(true)]
public class MyDataGridViewTextBoxColumn : System.Windows.Forms.DataGridViewTextBoxColumn
{
}
[System.Windows.Forms.DataGridViewColumnDesignTimeVisible(true)]
public class MyDataGridViewCheckBoxColumn : System.Windows.Forms.DataGridViewCheckBoxColumn
{
}
[System.Windows.Forms.DataGridViewColumnDesignTimeVisible(true)]
public class MyDataGridViewButtonColumn : System.Windows.Forms.DataGridViewButtonColumn
{
}
[System.Windows.Forms.DataGridViewColumnDesignTimeVisible(true)]
public class MyDataGridViewLinkColumn : System.Windows.Forms.DataGridViewLinkColumn
{
}
[System.Windows.Forms.DataGridViewColumnDesignTimeVisible(true)]
public class MyDataGridViewImageColumn : System.Windows.Forms.DataGridViewImageColumn
{
}
}
下面的图片显示了代码的结果