I have DataGridViewColumn that uses a DateTimePicker control in order to edit cell values. It's based off of the example given on MSDN.
I've run into two issues using this method to create a custom column: 1. The value in the cell reverts back to the current date even after the DateTimePicke开发者_如何学运维r has been altered. 2. Editing a DateTimePicker cell in the last row does not trigger the addition of a new row (I'm assuming this has to do with the previous issue).
How do I get the value picked in the DateTimePicker to be assigned to the textbox cell? I can provide code examples if necessary, but my control is almost identical to the MSDN link above.
The control that inherits from DateTimePicker and implements IDataGridViewEditingControl requires the OnValueChanged(...) event to be overridden in order to detect when an editing control has been altered. In order for the new value to bee assigned, the method must be overridden like so:
protected override void OnValueChanged(EventArgs eventargs)
{
this.EditingControlValueChanged = true;
this.EditingControlDataGridView.NotifyCurrentCellDirty(true);
base.OnValueChanged(eventargs);
}
As a side note, in the CalendarEditingControl class in the MSDN example there doesn't seem to be a need for the valueChanged
variable and the rowIndex
variables as these values can be handled by the EditingControlRowIndex and the EditingControlValueChanged respectively (if I read the example correctly).
MSDN Reference
精彩评论