Okay, I grabbed something potentially useful. It's the stack trace that came up in the pop-up when the error happened at runtime.
************** Exception Text **************
System.NullReferenceException: Object reference not set to an instance of an object.
at System.Windows.Forms.DataGridViewCell.GetEditedFormattedValue(Object value, Int32 rowIndex, DataGridViewCellStyle& dataGridViewCellStyle, DataGridViewDataErrorContexts context)
at System.Windows.Forms.DataGridViewCell.PaintWork(Graphics graphics, Rectangle clipBounds, Rectangle cellBounds, Int32 rowIndex, DataGridViewElementStates cellState, DataGridViewCellStyle cellStyle, DataGridViewAdvancedBorderStyle advancedBorderStyle, DataGridViewPaintParts paintParts)
at System.Windows.Forms.DataGridViewRow.PaintCells(Graphics graphics, Rectangle clipBounds, Rectangle rowBounds, Int32 rowIndex, DataGridViewElementStates rowState, Boolean isFirstDisplayedRow, Boolean isLastVisibleRow, DataGridViewPaintParts paintParts)
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.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
So it looks like my code was never touched here. I need to either figure out a way to actually catch that error and just move on, or prevent it from occurring in the first place. I'm not sure, but I get the impression it's a synchronization thing within DataGridView that's exposed by the high speed I'm changing the data at.
System.NullReferenceException: Object reference
it is quite obvious that one object is not yet initialised and used.
System.Windows.Forms.DataGridViewCell.GetEditedFormattedValue(Object value, Int32 rowIndex, DataGridViewCellStyle& dataGridViewCellStyle, DataGridViewDataErrorContexts context
referencing your datagrid at some moment.. thats all i can deduce.
I'm having the views die off, because (at least this seems to be how it's going down) the datagridview is trying to select a row that was just deleted as it was updated
......setting the DataAdapter's ContinueUpdateOnErrors property to True.......
maybe this can help alrite amigos.
hrubesh: These are DataGridView objects, not SQL DataAdapter objects. That would definitely be a useful-sounding thing to have, but it doesn't exist for these.
vkh75: I set the DataSource with _dataGridView1.DataSource = new DataView(_myData.Table);
When updates come in, I use _myData.Select("phrase") to get an array of rows, and set the values in those rows, or use the SetColumNameNull() method to set values null for them. In the background, I have a worker thread running, calling _myData.AcceptChanges() every second. But, evidently, the GUI isn't waiting for that method to be called to update itself. I'll get a burst of, say, eight hundred events, and the GUI'll update eight hundred times, and once in a while, when that happens, I get that paint error and one of my DataGridView elements dies off. It doesn't take the application down. I just end up with a red x where I'm supposed to have a list of data. I tried setting the RowStateFilter property, but that doesn't seem to be applicable. I basically want the GUI to wait until I call AcceptChanges to actually redraw itself. I may have to just buffer differently, but I don't tihnk I should have to.
Doogshnooglis wrote:
hrubesh: These are DataGridView objects, not SQL DataAdapter objects. That would definitely be a useful-sounding thing to have, but it doesn't exist for these.
truly: i got no idea of what's the difference for the time being.
In case this is of any use to anybody - I *partially* solved the issue with some strategies I found. Apparently there are some synchronization issues internal to these objects, and they're exposed by high-speed updating like I'm doing. I put BeginLoadData and EndLoadData calls around my LoadDataRow calls, and it lowered the occurrence of errors. I'm still winding up with dying data grid views, but not nearly as frequently. I'm going to try putting those calls around my updates to existing rows too, and see if that helps anything. I'm also getting row paint errors, and I think they have the same kind of cause, but not exactly the same. So that's the next hurdle - figuring out why it is that these are getting paint errors and fixing it, and handling the "Index 0 does not have a value" IORE that I'm hearing about in the dataerror event.
Just another update (it's good to have posts like this.. They come up in frustrated people's web searches)...
I wrapped updates to existing rows in calls to dataName.tableName.BeginInit() and dataName.tableName.EndInit() and it made a dent in the errors. They're still occurring on occasion, but not anywhere near as often. The last change I've made, though I haven't gotten to do any significant testing for longevity with it in place yet, is to set error.Cancel to true in the DataError event's handler. I was already doing error.ThrowException = false, but that didn't seem to have any effect.
Anybody able to throw any warnings my way on what setting Cancel to true may do? I mean - does it roll back the change to the data source, or just cancel the graphical update until next time, etc?
On a related note - is there, like, a row paint error event or something? Most of these problems would be solved if I could just handle that event by having it ignore the error and/or retry. It seems like fifty percent of the grid losses I've been having are because of those errors, and the rest have been the data errors.