Question Unhandled exception with datagridview

keb1965

Well-known member
Joined
Feb 9, 2009
Messages
103
Programming Experience
10+
I have a datagridview that has about 3500 records. This actually represents only a small portion of the total number of records that will be in this control when the application is rolled out.

The data is bound to many different controls in the aplication, but only a few with the ability to be edited. The datagridview itself is readonly, the only changes to the data are through the various controls.

The problem is that whenever a user might use the arrow keys to navigate the datagridview, an exception is thrown. Remember that while the user is changing records with the up or down arrow, no records are being edited.

System.InvalidOperationException: Operation is not valid because it results in a reentrant call to the SetCurrentCellAddressCore function.
at System.Windows.Forms.DataGridView.SetCurrentCellAddressCore(Int32 columnIndex, Int32 rowIndex, Boolean setAnchorCellAddress, Boolean validateCurrentCell, Boolean throughMouseClick)
at System.Windows.Forms.DataGridView.ProcessDownKeyInternal(Keys keyData, Boolean& moved)
at System.Windows.Forms.DataGridView.ProcessDataGridViewKey(KeyEventArgs e)
at System.Windows.Forms.DataGridView.OnKeyDown(KeyEventArgs e)
at System.Windows.Forms.Control.ProcessKeyEventArgs(Message& m)
at System.Windows.Forms.DataGridView.ProcessKeyEventArgs(Message& m)
at System.Windows.Forms.Control.ProcessKeyMessage(Message& m)
at System.Windows.Forms.Control.WmKeyChar(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)

If the selected row is only changed at the rate of about 1 per second, there is no exception. Since I can't edit the datagridview to deal with the exception, how might I resolve this?
 
It sounds like you are handling some event of the grid and then specifying the current cell. Is that the case? Are you handling any events of the grid or a bound BindingSource? If so, can we see the event handlers?
 
Actually I am not handling any events from the grid and I am not modifying any data directly.

First I created a data adapter and connected to an existing access database
On my form I placed a tabcontrol with various textboxes on each tab, directly below that tabcontrol I placed the datagridview and bound it to my data.
On about a dozen of my textboxes, I bound them to a specific column of data. Each textbox is read-only and cannot be changed by the user, it can only be changed programmatically.

In my program if the user clicks on an image, the mouse location is translated to a geopoints (it is a map of the US) and the textbox is programmatically changed .. this is important, since the textbox only changes when the user either clicks on the map, when the binding navigator is changed or if the user pickes a specific record in the datagrid. Also, the datagrid is only programmatically editable, no direct user edits to the data is allowed.

The only function I have written is the mouseclick event handler for my picturebox to translate the click point to a geopoint and put the geopoint into the proper textboxes, which will ultimately update the datasource since it is bound to the textbox control.

Now if the user is merely browsing the records too quickly (as in holding the up or down arrow keys or pressing it too quickly), the error is generated.

It is frustrating because a) if I am holding the down arrow key, I am not clicking on the map and subsequently not updating any data and b) I have verified that the there is no code written that tells the grid to update any cell. and c) no events are being handled from the grid or binding source.

Heck, at this point I am not even saving the edited data back to the database
 
Back
Top