示例#1
0
 protected override void OnEditingControlShowing(DataGridViewEditingControlShowingEventArgs e)
 {
     base.OnEditingControlShowing(e);
     if (e.Control is DataGridViewTextBoxEditingControl)
     {
         tb           = (DataGridViewTextBoxEditingControl)e.Control;
         tb.KeyPress += new KeyPressEventHandler(dataGridView_KeyPress);
     }
     else if (e.Control is CalendarEditingControl)
     {
         cld           = (CalendarEditingControl)e.Control;
         cld.KeyPress += new KeyPressEventHandler(dataGridView_KeyPress);
     }
     e.Control.KeyPress += new KeyPressEventHandler(dataGridView_KeyPress);
 }
示例#2
0
        public override void InitializeEditingControl(int rowIndex, object
                                                      initialFormattedValue, DataGridViewCellStyle dataGridViewCellStyle)
        {
            // Set the value of the editing control to the current cell value.
            base.InitializeEditingControl(rowIndex, initialFormattedValue,
                                          dataGridViewCellStyle);
            CalendarEditingControl ctl =
                DataGridView.EditingControl as CalendarEditingControl;

            // Use the default row value when Value property is null.
            if (this.Value == null || this.Value as DateTime? == new DateTime(1, 1, 1))
            {
                ctl.DateValue = (DateTime)this.DefaultNewRowValue;
            }
            else
            {
                ctl.DateValue = (DateTime)this.Value;
            }
        }