DataGridView: InvalidOperationException was unhandled

N

nvx

Hello,
I get the InvalidOperationException: "Operation did not succeed
because the program cannot commit or quit a cell value change." in
case I set value of a field in a data-bound DataGridView. Needless to
say this DataGridView is on a TabControl's TabPage which has not yet
been selected from the moment application has been run.

An example:
1. Let's run the application. Upon startup, we see the first TabPage
of the TabControl (say tabPage1). Our DataGridView is on another
TabPage, say tabPage2, so we do not see it now. We do not select
tabPage2 yet, thus preventing the DataGridView to be painted.
2. A certain method is run upon clicking a button in the toolbar. This
method changes value of a cell in our DataGridView, that is still
hidden.
3. Now, if we select tabPage2, InvalidOperationException: "Operation
did not succeed because the program cannot commit or quit a cell value
change." occurs.

In case user has already selected the TabPage containing the
DataGridView (even for an instant) before clicking the toolbar button
(and changing the cell's value), no exception occurs.

I believe something happens when the data-bound DataGridView is viewed
for the first time, but I do not know what it is. Any ideas what
should I do in tabControl_Selecting(...) or somewhere else to commit
the change to the cell and prevent this exception from occuring? I
know it would not occur if I used dataGridView.CancelEdit();, but this
resets the value of the changed cell to its previous value and I loose
the change I made...

Thanks a lot for any help...


Best regards
nvx
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top