日期:2014-05-20  浏览次数:20881 次

如何在一个DataGridView中的一列添加DateTimePicker控件
如何在一个DataGridView中的一列上添加DateTimePicker控件,

------解决方案--------------------
这个要自定义了,可能用到如下的几个类:
从DataGridViewColumn继承一个新的列类型
从DataGridViewCell继承一个新的单元类型.
从DateTimePicker, IDataGridViewEditingControl继承新的DateTimePicker控件,

------解决方案--------------------
你建个组件类,下面是源码,自已再贴上去

public class CalendarColumn : DataGridViewColumn
{

private bool showUpDown = true;

public bool ShowUpDown
{
get
{
return showUpDown;
}
set
{
showUpDown = value;
}
}

public CalendarColumn()
: base(new CalendarCell())
{
}

public override DataGridViewCell CellTemplate
{
get
{
return base.CellTemplate;
}
set
{

if (value != null &&
!value.GetType().IsAssignableFrom(typeof(CalendarCell)))
{
throw new InvalidCastException( "Must be a CalendarCell ");
}
base.CellTemplate = value;
}
}

private void InitializeComponent()
{

}
}