When you press delete the following code gets executed:
public virtual void RemoveRecords(int first, int last)
{
TraceUtil.TraceCurrentMethodInfoIf(Switches.Development.TraceVerbose,
first, last);
inRemoveRecords = true;
try
{
if (List != null &&
GridListUtil.GetAllowRemove(List))
{
gridModel.BeginUpdate(BeginUpdateOptions.InvalidateAndScroll);
for (int index = last; index >=
first; index--)
{
if (listManager != null)
ListManager.RemoveAt(index);
else
List.RemoveAt(index);
}
if (this.bindToCurrencyManager)
this.listManager_PositionChanged(ListManager, EventArgs.Empty);
this.OnRowChanged(EventArgs.Empty);
this.OnRecordsRemoved(EventArgs.Empty);
gridModel.EndUpdate(true);
}
}
finally
{
inRemoveRecords = false;
}
}
The exception gets thrown when
ListManager.RemoveAt(index);
Is called. It is the following exception:
A first chance exception of type ''System.ArgumentException'' occurred in system.windows.forms.dll
Additional information: ''1/1/0001 12:00:00 AM'' is not a valid value for ''Value''. ''Value'' should be between ''MinDate'' and ''MaxDate''.
With the following call stack:
system.windows.forms.dll!System.Windows.Forms.DateTimePicker.set_Value(System.DateTime value = {1/1/1}) + 0x173 bytes
system.dll!System.ComponentModel.ReflectPropertyDescriptor.SetValue(System.Object component = {Value={12/30/9998}}, System.Object value =) + 0x189 bytes
system.windows.forms.dll!System.Windows.Forms.Binding.SetPropValue(System.Object value = ) + 0x101 bytes
system.windows.forms.dll!System.Windows.Forms.Binding.PushData()+ 0x50 bytes
system.windows.forms.dll!System.Windows.Forms.BindingManagerBase.PushData() + 0x59 bytes
system.windows.forms.dll!System.Windows.Forms.CurrencyManager.CurrencyManager_PushData() + 0x47 bytes
system.windows.forms.dll!System.Windows.Forms.CurrencyManager.OnItemChanged(System.Windows.Forms.ItemChangedEventArgs e = {Index=-1}) + 0x78 bytes
system.windows.forms.dll!System.Windows.Forms.CurrencyManager.UpdateIsBinding(bool force = false) + 0x122 bytes
system.windows.forms.dll!System.Windows.Forms.CurrencyManager.UpdateIsBinding() + 0xd bytes
system.windows.forms.dll!System.Windows.Forms.CurrencyManager.List_ListChanged(System.Object sender = {System.Data.DataView},System.ComponentModel.ListChangedEventArgs e = {System.ComponentModel.ListChangedEventArgs}) + 0x133 bytes
system.data.dll!System.Data.DataView.OnListChanged(System.ComponentModel.ListChangedEventArgs e = {System.ComponentModel.ListChangedEventArgs})+ 0x48 bytes
system.data.dll!System.Data.DataView.IndexListChanged(System.Object sender = {System.Data.Index}, System.ComponentModel.ListChangedEventArgs e = {System.ComponentModel.ListChangedEventArgs}) + 0x43 bytes
system.data.dll!System.Data.DataView.FireEvent(System.Data.TargetEvent targetEvent = IndexListChanged, System.Object sender = {System.Data.Index}, System.EventArgs e = {System.ComponentModel.ListChangedEventArgs}) + 0x4c bytes
system.data.dll!System.Data.DataViewListener.IndexListChanged(System.Object sender = {System.Data.Index}, System.ComponentModel.ListChangedEventArgs e = {System.ComponentModel.ListChangedEventArgs}) + 0x3d bytes
system.data.dll!System.Data.Index.OnListChanged(System.ComponentModel.ListChangedEventArgs e = {System.ComponentModel.ListChangedEventArgs}) + 0x29 bytes
system.data.dll!System.Data.Index.DeleteRecord(int recordIndex = 0) + 0x4d bytes
system.data.dll!System.Data.Index.ApplyChangeAction(int record = 0, int action = -1) + 0x73 bytes
system.data.dll!System.Data.Index.RecordStateChanged(int record = 0, System.Data.DataViewRowState oldState = Added, System.Data.DataViewRowState newState = None) + 0x34 bytes
system.data.dll!System.Data.DataTable.RecordStateChanged(int record1 = 0, System.Data.DataViewRowState oldState1 = Added, System.Data.DataViewRowState newState1 = None, int record2 = -1, System.Data.DataViewRowState oldState2 = None, System.Data.DataViewRowState newState2 = None) + 0xc0 bytes
system.data.dll!System.Data.DataTable.SetNewRecord(System.Data.DataRow row = {System.Data.DataRow}, int proposedRecord = -1, System.Data.DataRowAction action = Delete, bool isInMerge = false) + 0x230 bytes
system.data.dll!System.Data.DataTable.DeleteRow(System.Data.DataRow row = {System.Data.DataRow}) + 0x32 bytes
system.data.dll!System.Data.DataRow.Delete() + 0x3f bytes
system.data.dll!System.Data.DataView.Delete(int index = 0) + 0x80 bytes
system.data.dll!System.Data.DataView.System.Collections.IList.RemoveAt(int index = 0) + 0x16 bytes
system.windows.forms.dll!System.Windows.Forms.CurrencyManager.RemoveAt(int index = 0) + 0x1b bytes
syncfusion.grid.windows.dll!Syncfusion.Windows.Forms.Grid.GridModelDataBinder.RemoveRecords(int first = 0, int last = 0) Line 2955 + 0x14 bytes
The reason for this exception is that the DateTimePicker is bound to the same ListManager as the grid. When the grid removes the only record by calling ListManager.Remove the ListManager resets all values for the record and notifies all controls that are bound to the ListManager. Therefore it also notifies the DateTimePicker and assign a null value to it. The DateTimePicker then throws an exception.
You can workaround the problem by making sure that one row remains in the CurrencyManager when you delete the last row.
In the bmb_PositionChanged you can check for CurrenyManager.Count = 0
private void bmb_PositionChanged(object sender, EventArgs e)
{
CurrencyManager cm = sender as CurrencyManager;
if (cm != null && cm.Count == 0)
{
this.NewSerienauftrag(0);
}
RefreshRadioButtons();
BeginEnableDisable();
}