I have the following bit of code...
I have a DataGridView, which is bound to a BindingSource. I then bind a child
collection to the binding source, before doing so, I turn off the event
listener, set the bS.Datasource to null, and then bind my new child collection.
When I do this, my application seems to just close without a single warning. I
did get the application to crash before if I didn't turn off the event listener
(call stack below), does anyone have any ideas?
Background: I'm using a third party tool to handle docking in my application. I
did check the event log and the only item logged was a failure audit, but my
object was loaded.
Message="Object
reference not set to an instance of an object."
Source="System.Windows.Forms"
StackTrace:
at
System.Windows.Forms.DataGridViewRow.GetErrorText(Int32 rowIndex)
at
System.Windows.Forms.DataGridViewRow.Paint(Graphics graphics, Rectangle
clipBounds, Rectangle rowBounds, Int32 rowIndex, DataGridViewElementStates
rowState, Boolean isFirstDisplayedRow, Boolean isLastVisibleRow)
at
System.Windows.Forms.DataGridView.PaintRows(Graphics g, Rectangle boundingRect,
Rectangle clipRect, Boolean singleHorizontalBorderAdded)
at
System.Windows.Forms.DataGridView.PaintGrid(Graphics g, Rectangle gridBounds,
Rectangle clipRect, Boolean singleVerticalBorderAdded, Boolean singleHorizontalBorderAdded)
at
System.Windows.Forms.DataGridView.OnPaint(PaintEventArgs e)
at
System.Windows.Forms.Control.PaintWithErrorHandling(PaintEventArgs e, Int16
layer, Boolean disposeEventArgs)
at
System.Windows.Forms.Control.WmPaint(Message& m)
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)
Are you also binding the parent object to another bindingsource? If so, you probably shouldn't set the child bindingsource to null, but rather to the parent bindingsource
http://www.lhotka.net/Cs2005Errata.aspx?id=6432c872-92ce-4bb8-bc26-b610b71956c8
I have run into similar null reference issues, and it is usually due to a linkage between data binding objects that triggers an attempted refresh of data when you don't have any data available because you've set something to null.
Copyright (c) Marimer LLC