We have a DataGridView on a form that can be filtered based on a user checkbox to show or hide rows with a column whose value is empty. This is done by setting the Filter property on our BindingSource to "MyColumn <> ''" when the checkbox is checked.
When the user is looking at the filtered view of the records, they can edit MyColumn's value and remove everything from it, causing it to no longer pass the filter. When they click to a new row with an empty string in MyColumn, the row drops from the list and we can verify that the changes were made to the database (as expected).
The program finishes all our code (verified by stepping into everything we have) and then the next thing we can find that gets called is the Dispose method of the form. A breakpoint in there shows an exception that gives a "Object reference not set to an instance of an object." message. We also have a try/catch around the Main method that catches this exception.
The exception's Stack Trace is as follows:
at System.Data.DataView.FinishAddNew(Int32 currentIndex, Boolean success) at System.Data.DataRowView.EndEdit() at System.Windows.Forms.CurrencyManager.EndCurrentEdit() at System.Windows.Forms.CurrencyManager.ChangeRecordState(Int32 newPosition, Boolean validating, Boolean endCurrentEdit, Boolean firePositionChange, Boolean pullData) at System.Windows.Forms.CurrencyManager.List_ListChanged(Object sender, ListChangedEventArgs e) at System.Windows.Forms.BindingSource.OnListChanged(ListChangedEventArgs e) at System.Windows.Forms.BindingSource.InnerList_ListChanged(Object sender, ListChangedEventArgs e) at System.Data.DataView.OnListChanged(ListChangedEventArgs e) at System.Data.DataView.IndexListChanged(Object sender, ListChangedEventArgs e) at System.Data.DataViewListener.IndexListChanged(Object sender, ListChangedEventArgs e) at System.Data.Index.OnListChanged(ListChangedType changedType, Int32 index) at System.Data.Index.InsertRecord(Int32 record, Boolean fireEvent) at System.Data.Index.ApplyChangeAction(Int32 record, Int32 action) at System.Data.Index.RecordStateChanged(Int32 oldRecord, DataViewRowState oldOldState, DataViewRowState oldNewState, Int32 newRecord, DataViewRowState newOldState, DataViewRowState newNewState) at System.Data.DataTable.RecordStateChanged(Int32 record1, DataViewRowState oldState1, DataViewRowState newState1, Int32 record2, DataViewRowState oldState2, DataViewRowState newState2) at System.Data.DataTable.SetNewRecordWorker(DataRow row, Int32 proposedRecord, DataRowAction action, Boolean isInMerge, Int32 position, Boolean fireEvent, Exception& deferredException) at System.Data.DataTable.SetNewRecord(DataRow row, Int32 proposedRecord, DataRowAction action, Boolean isInMerge, Boolean fireEvent) at System.Data.DataRow.EndEdit() at System.Data.DataRowView.EndEdit() at System.Windows.Forms.CurrencyManager.EndCurrentEdit() at System.Windows.Forms.DataGridView.DataGridViewDataConnection.OnRowValidating(DataGridViewCellCancelEventArgs e) at System.Windows.Forms.DataGridView.OnRowValidating(DataGridViewCell& dataGridViewCell, Int32 columnIndex, Int32 rowIndex) at System.Windows.Forms.DataGridView.CommitEdit(DataGridViewDataErrorContexts context, Boolean forCurrentCellChange, Boolean forCurrentRowChange) at System.Windows.Forms.DataGridView.OnCellMouseDown(HitTestInfo hti, Boolean isShiftDown, Boolean isControlDown) at System.Windows.Forms.DataGridView.OnCellMouseDown(DataGridViewCellMouseEventArgs e) at System.Windows.Forms.DataGridView.OnMouseDown(MouseEventArgs e) at System.Windows.Forms.Control.WmMouseDown(Message& m, MouseButtons button, Int32 clicks) at System.Windows.Forms.Control.WndProc(Message& m) at System.Windows.Forms.DataGridView.WndProc(Message& m) at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m) at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m) at System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam) at System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG& msg) at System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(Int32 dwComponentID, Int32 reason, Int32 pvLoopData) at System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context) at System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context) at System.Windows.Forms.Application.Run(Form mainForm) at Mitinet.Zelda.Program.Main() in C:\ITI\Zelda\ZeldaViewer\Program.cs:line 19 |
Any insight would be appreciated!

Dispose called after edited filter row disappears