Bug Report B149499
Visible to All Users

NullReferenceException when editing in an detail grid and reloading datasource

created 15 years ago

When editing values in an detail grid and reloading the datasource after the new property value has been assigned by handling the ListChanged-Event of the datasource, a NullReferenceException occurs. It happens both when tabbing out of the column and when focusing another column by mouse click.
Moving focus with mouse click:
" bei DevExpress.XtraGrid.Views.Grid.Handler.GridHandler.get_DownPointHitInfo()\r\n bei DevExpress.XtraGrid.Views.Grid.Handler.GridHandler.OnMouseDown(MouseEventArgs ev)\r\n bei DevExpress.Utils.Controls.BaseHandler.ProcessEvent(EventType etype, Object args)\r\n bei DevExpress.XtraGrid.Views.Base.Handler.BaseViewHandler.ProcessEvent(EventType etype, Object args)\r\n bei DevExpress.XtraGrid.GridControl.OnMouseDown(MouseEventArgs ev)\r\n bei System.Windows.Forms.Control.WmMouseDown(Message& m, MouseButtons button, Int32 clicks)\r\n bei System.Windows.Forms.Control.WndProc(Message& m)\r\n bei DevExpress.XtraEditors.Container.EditorContainer.WndProc(Message& m)\r\n bei DevExpress.XtraGrid.GridControl.WndProc(Message& m)\r\n bei System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)\r\n bei System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)\r\n bei System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)\r\n bei System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG& msg)\r\n bei System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(Int32 dwComponentID, Int32 reason, Int32 pvLoopData)\r\n bei System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context)\r\n bei System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context)\r\n bei System.Windows.Forms.Application.Run(ApplicationContext context)\r\n bei Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.OnRun()\r\n bei Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.DoApplicationModel()\r\n bei Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.Run(String[] commandLine)\r\n bei WindowsApplication1.My.MyApplication.Main(String[] Args) in 17d14f5c-a337-4978-8281-53493378c1071.vb:Zeile 81.\r\n bei System.AppDomain._nExecuteAssembly(Assembly assembly, String[] args)\r\n bei System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)\r\n bei Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()\r\n bei System.Threading.ThreadHelper.ThreadStart_Context(Object state)\r\n bei System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)\r\n bei System.Threading.ThreadHelper.ThreadStart()"
Tabbing out:
" bei DevExpress.XtraGrid.Views.Base.ColumnView.AccessibleNotifyClients(Int32 row, GridColumn focusedCol)\r\n bei DevExpress.XtraGrid.Views.Base.ColumnView.RaiseFocusedColumnChanged(GridColumn prevFocused, GridColumn focusedColumn)\r\n bei DevExpress.XtraGrid.Views.Base.ColumnView.DoAfterFocusedColumnChanged(GridColumn prevFocusedColumn, GridColumn focusedColumn)\r\n bei DevExpress.XtraGrid.Views.Grid.GridView.DoAfterFocusedColumnChanged(GridColumn prevFocusedColumn, GridColumn focusedColumn)\r\n bei DevExpress.XtraGrid.Views.Base.ColumnView.set_FocusedColumn(GridColumn value)\r\n bei DevExpress.XtraGrid.Views.Grid.Handler.GridHandler.DoMoveFocusedColumn(Int32 delta, Boolean autoMoveRowFocus, KeyEventArgs e)\r\n bei DevExpress.XtraGrid.Views.Grid.Handler.GridRegularRowNavigator.DoNavigation(KeyEventArgs e)\r\n bei DevExpress.XtraGrid.Views.Grid.Handler.GridRegularRowNavigator.OnKeyDown(KeyEventArgs e)\r\n bei DevExpress.XtraGrid.Views.Grid.Handler.GridHandler.OnKeyDown(KeyEventArgs e)\r\n bei DevExpress.XtraGrid.Views.Grid.Handler.GridHandler.ProcessKey(KeyEventArgs e)\r\n bei DevExpress.Utils.Controls.BaseHandler.ProcessEvent(EventType etype, Object args)\r\n bei DevExpress.XtraGrid.Views.Base.Handler.BaseViewHandler.ProcessEvent(EventType etype, Object args)\r\n bei DevExpress.XtraGrid.GridControl.RaiseEditorKeyDown(KeyEventArgs e)\r\n bei DevExpress.XtraEditors.Container.EditorContainer.DevExpress.XtraEditors.Container.IEditorContainer.OnEditorKeyDown(KeyEventArgs e)\r\n bei DevExpress.XtraEditors.BaseEdit.OnEditorKeyDown(KeyEventArgs e)\r\n bei DevExpress.XtraEditors.TextEdit.OnEditorKeyDown(KeyEventArgs e)\r\n bei DevExpress.XtraEditors.BaseEdit.OnKeyDown(KeyEventArgs e)\r\n bei DevExpress.XtraEditors.TextEdit.OnMaskBox_KeyDown(Object sender, KeyEventArgs e)\r\n bei System.Windows.Forms.Control.OnKeyDown(KeyEventArgs e)\r\n bei DevExpress.XtraEditors.Mask.MaskBox.OnKeyDown(KeyEventArgs e)\r\n bei System.Windows.Forms.Control.ProcessKeyEventArgs(Message& m)\r\n bei DevExpress.XtraEditors.Mask.MaskBox.ProcessKeyEventArgs(Message& m)\r\n bei System.Windows.Forms.Control.ProcessKeyMessage(Message& m)\r\n bei System.Windows.Forms.Control.WmKeyChar(Message& m)\r\n bei System.Windows.Forms.Control.WndProc(Message& m)\r\n bei System.Windows.Forms.TextBoxBase.WndProc(Message& m)\r\n bei System.Windows.Forms.TextBox.WndProc(Message& m)\r\n bei DevExpress.XtraEditors.Mask.MaskBox.BaseWndProc(Message& m)\r\n bei DevExpress.XtraEditors.Mask.MaskBox.MaskStrategy.SimpleStrategy.DoWndProc(Message& m)\r\n bei DevExpress.XtraEditors.Mask.MaskBox.WndProc(Message& m)\r\n bei DevExpress.XtraEditors.TextBoxMaskBox.WndProc(Message& msg)\r\n bei System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)\r\n bei System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)\r\n bei System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)\r\n bei System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG& msg)\r\n bei System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(Int32 dwComponentID, Int32 reason, Int32 pvLoopData)\r\n bei System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context)\r\n bei System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context)\r\n bei System.Windows.Forms.Application.Run(ApplicationContext context)\r\n bei Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.OnRun()\r\n bei Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.DoApplicationModel()\r\n bei Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.Run(String[] commandLine)\r\n bei WindowsApplication1.My.MyApplication.Main(String[] Args) in 17d14f5c-a337-4978-8281-53493378c1071.vb:Zeile 81.\r\n bei System.AppDomain._nExecuteAssembly(Assembly assembly, String[] args)\r\n bei System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)\r\n bei Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()\r\n bei System.Threading.ThreadHelper.ThreadStart_Context(Object state)\r\n bei System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)\r\n bei System.Threading.ThreadHelper.ThreadStart()"
Steps to Reproduce:

  1. start attached sample application
  2. expand any master row
  3. edit one of the values in the price column of the detail gridview
  4. press tab or click with mouse on another column in detail grid
    Actual Results:
    NullReferenceException

Answers approved by DevExpress Support

created 15 years ago (modified 12 years ago)

Hi Matthias,
Thank you for the sample project. It was very helpful.
It's not a bug. The cause of the problem is that refreshing the GridView breaks normal message processing. To solve the problem, you need to execute your code using the BeginInvoke method. This will resolve the problem.
I've modified your project to illustrate this solution.
If you need any further assistance on this subject, please feel free to reactivate this ticket.
Thanks
Dimitros

    Comments (3)

      Why is this not considered a bug??

      The GridControl have the IsInvokeRequired set to false - så why do we need to invoke it?
      also - why call BeginInvoke instead of Invoke ?

      DevExpress Support Team 12 years ago

        Hello Jens,
        This is not a bug, because the problem occurs when the datasource is modified in the BindingSource.ListChanged event handler. All data bound controls subscribe to this event to refresh their visual state according to changes in the datasource. Any changes in the datasource at this moment can repeat the refresh process while the previous one is not yet complete. We suggest to either not modify the datasource in the ListChanged event handler, or to postpone this operation using the BeginInvoke method.

          Thank you for explaning that.

          Disclaimer: The information provided on DevExpress.com and affiliated web properties (including the DevExpress Support Center) is provided "as is" without warranty of any kind. Developer Express Inc disclaims all warranties, either express or implied, including the warranties of merchantability and fitness for a particular purpose. Please refer to the DevExpress.com Website Terms of Use for more information in this regard.

          Confidential Information: Developer Express Inc does not wish to receive, will not act to procure, nor will it solicit, confidential or proprietary materials and information from you through the DevExpress Support Center or its web properties. Any and all materials or information divulged during chats, email communications, online discussions, Support Center tickets, or made available to Developer Express Inc in any manner will be deemed NOT to be confidential by Developer Express Inc. Please refer to the DevExpress.com Website Terms of Use for more information in this regard.