System.InvalidOperationException was unhandled Message="Operation is not valid because it results in a reentrant call to the SetCurrentCellAddressCore function."
In fact I had to repopulate the datagridview on CellEndEdit. I Googled a lot about it and found some solutions. I came up to something, which I am not sure is the most efficient one, but it works.
public delegate void InvokeDelegate(); private void datagrid_changed(object sender, EventArgs e) { this.dataGridView.BeginInvoke(new InvokeDelegate(ModifyGrid)); } private void ModifyGrid() { // Method implemented to change datasource }
Instead of modifying the datasource directly, I had to pass though a delegated called by BeginInvoke. It should work fine.
In WPF DataGrid it is as follows:
private void dataGridLines_RowEditEnding(object sender, EventArgs e) { Dispatcher.BeginInvoke(new InvokeDelegate(InsertRow), null); }
Thank you so much for posting this. I had the same problem and this is the only thing that has worked for me.
ReplyDeletethanks
ReplyDeleteThks!
ReplyDeletethks a lot ! vb.net version :
ReplyDeletePublic Delegate Sub InvokeDelegate()
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
dgReassort.BeginInvoke(New InvokeDelegate(AddressOf Me.refreshDgReassort))
End Sub
Public Sub refreshDatagrid()
datagrid.datasource = '...'
End Sub
This code allow you leave the cell while refreshing data
Nice blog posst
ReplyDelete