{"id":2934,"date":"2014-03-10T13:01:28","date_gmt":"2014-03-10T13:01:28","guid":{"rendered":"https:\/\/unknownerror.org\/index.php\/2014\/03\/10\/datagridview-crashes-onpaint-when-stepping-thru-debugger-can-never-be-reproduced-collection-of-common-programming-errors\/"},"modified":"2014-03-10T13:01:28","modified_gmt":"2014-03-10T13:01:28","slug":"datagridview-crashes-onpaint-when-stepping-thru-debugger-can-never-be-reproduced-collection-of-common-programming-errors","status":"publish","type":"post","link":"https:\/\/unknownerror.org\/index.php\/2014\/03\/10\/datagridview-crashes-onpaint-when-stepping-thru-debugger-can-never-be-reproduced-collection-of-common-programming-errors\/","title":{"rendered":"DatagridView Crashes OnPaint. When stepping thru debugger can never be reproduced.-Collection of common programming errors"},"content":{"rendered":"<p>I&#8217;m having a really annoying and serious problem happening with DataGridView&#8230;<\/p>\n<p>I have typed dataset in memory wich I fill via a background worker.<\/p>\n<p>Once it finishes sucessfully, I enable some grids to show that data.<\/p>\n<p>On selection changed, I disable all the grids so the user doesen&#8217;t click the same grid and try to run the\u00a0second worker\u00a0two times at the same time.\u00a0the second background worker retrieves some data and puts it into the same object on Form1, does some comparisons etc&#8230;.<\/p>\n<p>The problem is when i click on ANYTHING to change the selection in the first grid&#8230; I have no code On_Paint.\u00a0 I explicitly check for a selected row count to make sure something is there before i read it&#8217;s value.<\/p>\n<p>but i get this error:<\/p>\n<p>DataGridView Default Error<\/p>\n<p>IndexOutOfRange Index 0 does not have a value.<\/p>\n<p>Note that I&#8217;ve stepped into the debugger and the error DOES NOT occur. Only when I&#8217;m not stepping thru it is when it happens, making sure that i stepped into all running threads. I don&#8217;t think this is my code&#8217;s bug at this point but who knows.<\/p>\n<p>Then i get taken to the dissasembler display with the following error:<\/p>\n<p>&#8220;Object reference not set to an instance of an object.&#8221;\u00a0<\/p>\n<p>\u00a0 at System.Windows.Forms.DataGridViewRow.GetErrorText(Int32 rowIndex)\u00a0\u00a0 at System.Windows.Forms.DataGridViewRow.Paint(Graphics graphics, Rectangle clipBounds, Rectangle rowBounds, Int32 rowIndex, DataGridViewElementStates rowState, Boolean isFirstDisplayedRow, Boolean isLastVisibleRow)\u00a0\u00a0 at System.Windows.Forms.DataGridView.PaintRows(Graphics g, Rectangle boundingRect, Rectangle clipRect, Boolean singleHorizontalBorderAdded)\u00a0\u00a0 at System.Windows.Forms.DataGridView.PaintGrid(Graphics g, Rectangle gridBounds, Rectangle clipRect, Boolean singleVerticalBorderAdded, Boolean singleHorizontalBorderAdded)\u00a0\u00a0 at System.Windows.Forms.DataGridView.OnPaint(PaintEventArgs e)\u00a0\u00a0 at System.Windows.Forms.Control.PaintWithErrorHandling(PaintEventArgs e, Int16 layer, Boolean disposeEventArgs)\u00a0\u00a0 at System.Windows.Forms.Control.WmPaint(Message&amp; m)\u00a0\u00a0 at System.Windows.Forms.Control.WndProc(Message&amp; m)\u00a0\u00a0 at System.Windows.Forms.DataGridView.WndProc(Message&amp; m)\u00a0\u00a0 at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message&amp; m)\u00a0\u00a0 at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message&amp; m)\u00a0\u00a0 at System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)\u00a0\u00a0 at System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG&amp; msg)\u00a0\u00a0 at System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(Int32 dwComponentID, Int32 reason, Int32 pvLoopData)\u00a0\u00a0 at System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context)\u00a0\u00a0 at System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context)\u00a0\u00a0 at System.Windows.Forms.Application.Run(ApplicationContext context)\u00a0\u00a0 at Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.OnRun()\u00a0\u00a0 at Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.DoApplicationModel()\u00a0\u00a0 at Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.Run(String[] commandLine)<\/p>\n<p>\u00a0\u00a0 at Receiving_Specialist.My.MyApplication.Main(String[] Args) in 17d14f5c-a337-4978-8281-53493378c1071.vb:line 81<\/p>\n<p>this is the only place where it could be but that code needs to be there and it seems safe enough no?<\/p>\n<p>If Me.dg_OrderList.SelectedRows.Count &gt; 0 Then<\/p>\n<p>CurrentOrder =<\/p>\n<p>Me.dg_OrderList.SelectedRows(0).Cells(&#8220;OrderNoDataGridViewTextBoxColumn2&#8221;).ValueEnd If<\/p>\n","protected":false},"excerpt":{"rendered":"<p>I&#8217;m having a really annoying and serious problem happening with DataGridView&#8230; I have typed dataset in memory wich I fill via a background worker. Once it finishes sucessfully, I enable some grids to show that data. On selection changed, I disable all the grids so the user doesen&#8217;t click the same grid and try to [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-2934","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/2934","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/comments?post=2934"}],"version-history":[{"count":0,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/2934\/revisions"}],"wp:attachment":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/media?parent=2934"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/categories?post=2934"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/tags?post=2934"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}