Problem with RowChanging event
Hi,
if have a DataSet (SQLExpress) whith 2 Tables.
On one table I add a RowChanging event handler.
When I add a record in a boud datagridview then an exception occures in the handler. (After changing the postion in the DGV the event is fired).
Here my handler:
void PCs_RowChanging(object sender,DataRowChangeEventArgs e) { if (PCsBindingSource.IsBindingSuspended) { return; } try { MessageBox.Show(e.Action.ToString()); } catch(Exception eX) { MessageBox.Show(eX.Message); } } |
I get and "Index out of range" exception and my DGV is a red rectangle with red lines across it.
After the exception I can see my MessageBox telling "Add".
For changes the things work fine - but the Add makes problems if I show the Messgebox - if I do nothing (comment out the messagebox)- no problems occure!
The error comes up even if I only call MessageBox.Show("Hello");
Here is the stacktrace of the error:
************** Exception Text **************
System.IndexOutOfRangeException: Index 2 does not have a value.
at System.Windows.Forms.CurrencyManager.get_Item(Int32 index)
at System.Windows.Forms.DataGridView.DataGridViewDataConnection.GetError(Int32 rowIndex)
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.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
Is this a bug - or do I miss something?
Cheers
Manfred

