两个文件:
 
CalendarColumn 类:
- public class CalendarColumn : DataGridViewColumn  
 
-     {  
 
-         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;  
 
-             }  
 
-         }  
 
-     }  
 
**********************************************************************
CalendarCell 类:
- public class CalendarCell : DataGridViewTextBoxCell  
 
-     {  
 
-   
 
-         public CalendarCell()  
 
-             : base()  
 
-         {  
 
-             
 
-             this.Style.Format = "d";  
 
-         }  
 
-   
 
-         public override void InitializeEditingControl(int rowIndex, object  
 
-             initialFormattedValue, DataGridViewCellStyle dataGridViewCellStyle)  
 
-         {  
 
-             
 
-             base.InitializeEditingControl(rowIndex, initialFormattedValue,  
 
-                 dataGridViewCellStyle);  
 
-             CalendarEditingControl ctl =  
 
-                 DataGridView.EditingControl as CalendarEditingControl;  
 
-             if (this.Value == null)  
 
-                 ctl.Value = DateTime.Now;  
 
-             else  
 
-                 ctl.Value = (DateTime)this.Value;  
 
-         }  
 
-   
 
-         public override Type EditType  
 
-         {  
 
-             get  
 
-             {  
 
-                 
 
-                 return typeof(CalendarEditingControl);  
 
-             }  
 
-         }  
 
-   
 
-         public override Type ValueType  
 
-         {  
 
-             get  
 
-             {  
 
-                 
 
-                 return typeof(DateTime);  
 
-             }  
 
-         }  
 
-   
 
-         public override object DefaultNewRowValue  
 
-         {  
 
-             get  
 
-             {  
 
-                 
 
-                 return DateTime.Now;  
 
-             }  
 
-         }  
 
-     }  
 
-   
 
-     class CalendarEditingControl : DateTimePicker, IDataGridViewEditingControl  
 
-     {  
 
-         DataGridView dataGridView;  
 
-         private bool valueChanged = false;  
 
-         int rowIndex;  
 
-   
 
-         public CalendarEditingControl()  
 
-         {  
 
-             this.Format = DateTimePickerFormat.Short;  
 
-         }  
 
-   
 
-         
 
-         
 
-         public object EditingControlFormattedValue  
 
-         {  
 
-             get  
 
-             {  
 
-                 return this.Value.ToShortDateString();  
 
-             }  
 
-             set  
 
-             {  
 
-                 String newValue = value as String;  
 
-                 if (newValue != null)  
 
-                 {  
 
-                     this.Value = DateTime.Parse(newValue);  
 
-                 }  
 
-             }  
 
-         }  
 
-   
 
-         
 
-         
 
-         public object GetEditingControlFormattedValue(  
 
-             DataGridViewDataErrorContexts context)  
 
-         {  
 
-             return EditingControlFormattedValue;  
 
-         }  
 
-   
 
-         
 
-         
 
-         public void ApplyCellStyleToEditingControl(  
 
-             DataGridViewCellStyle dataGridViewCellStyle)  
 
-         {  
 
-             this.Font = dataGridViewCellStyle.Font;  
 
-             this.CalendarForeColor = dataGridViewCellStyle.ForeColor;  
 
-             this.CalendarMonthBackground = dataGridViewCellStyle.BackColor;  
 
-         }  
 
-   
 
-         
 
-         
 
-         public int EditingControlRowIndex  
 
-         {  
 
-             get  
 
-             {  
 
-                 return rowIndex;  
 
-             }  
 
-             set  
 
-             {  
 
-                 rowIndex = value;  
 
-             }  
 
-         }  
 
-   
 
-         
 
-         
 
-         public bool EditingControlWantsInputKey(  
 
-             Keys key, bool dataGridViewWantsInputKey)  
 
-         {  
 
-             
 
-             switch (key & Keys.KeyCode)  
 
-             {  
 
-                 case Keys.Left:  
 
-                 case Keys.Up:  
 
-                 case Keys.Down:  
 
-                 case Keys.Right:  
 
-                 case Keys.Home:  
 
-                 case Keys.End:  
 
-                 case Keys.PageDown:  
 
-                 case Keys.PageUp:  
 
-                     return true;  
 
-                 default:  
 
-                     return false;  
 
-             }  
 
-         }  
 
-   
 
-         
 
-         
 
-         public void PrepareEditingControlForEdit(bool selectAll)  
 
-         {  
 
-             
 
-         }  
 
-   
 
-         
 
-         
 
-         public bool RepositionEditingControlOnValueChange  
 
-         {  
 
-             get  
 
-             {  
 
-                 return false;  
 
-             }  
 
-         }  
 
-   
 
-         
 
-         
 
-         public DataGridView EditingControlDataGridView  
 
-         {  
 
-             get  
 
-             {  
 
-                 return dataGridView;  
 
-             }  
 
-             set  
 
-             {  
 
-                 dataGridView = value;  
 
-             }  
 
-         }  
 
-   
 
-         
 
-         
 
-         public bool EditingControlValueChanged  
 
-         {  
 
-             get  
 
-             {  
 
-                 return valueChanged;  
 
-             }  
 
-             set  
 
-             {  
 
-                 valueChanged = value;  
 
-             }  
 
-         }  
 
-   
 
-         
 
-         
 
-         public Cursor EditingPanelCursor  
 
-         {  
 
-             get  
 
-             {  
 
-                 return base.Cursor;  
 
-             }  
 
-         }  
 
-   
 
-         protected override void OnValueChanged(EventArgs eventargs)  
 
-         {  
 
-             
 
-             
 
-             valueChanged = true;  
 
-             this.EditingControlDataGridView.NotifyCurrentCellDirty(true);  
 
-             base.OnValueChanged(eventargs);  
 
-         }  
 
-     }  
 
*****************************************************************
调用,和DataGridViewTextBoxColumn一样
    private CalendarColumn awardsDate;
    this.awardsDate = new CalendarColumn();
    this.awardsDate.DataPropertyName = "awardsDate";
    this.awardsDate.HeaderText = "颁奖日期";
    this.awardsDate.Name = "awardsDate";
    this.Columns.AddRange(new System.Windows.Forms.DataGridViewColumn[] {
            this.awardsDate});
 
可以新增、赋值、编辑该列。
 
DataGridView控件内建立日期选择编辑列
原文:http://www.cnblogs.com/wanzhongjun/p/6250073.html