简体   繁体   中英

Custom DataGridView column not persisting changes

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 DateTimePicker 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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM