Note that there are some explanatory texts on larger screens.

plurals
  1. POHow can I force a commit on the current row from within a virtual unbound DataGridView's edit control event handler?
    text
    copied!<p>Using the walkthrough from [[http://msdn.microsoft.com/de-de/library/15a31akc.aspx]], I implemented a <code>DatagridView</code> in virtual mode, totally unbound, in VB 10 Express (we are talking WinForms).</p> <p>I understand that <code>CommitEdit (DataGridViewDataErrorContexts.Commit)</code> commits the current cell's contents to the data cache.</p> <p>The example uses row-level commit, i.e. it pushes the values into a row buffer until the current row is left. Only then the row is added to (or updated in) the data store. That's exactly what I do, too.</p> <p><strong>Question -- how can I commit the current row programmatically without leaving it?</strong> (I want to commit the whole row, not just the current cell.) </p> <p>If the user leaves the row, there is a <code>RowValidating</code>, <code>RowValidated</code>, <code>RowEnter</code> event sequence where the datastore update is taken care of. So one idea (currently my only one) was to simply re-set <code>CurrentCell</code> to <code>Nothing</code>, for example.</p> <p>But I cannot just set the <code>DataGridView</code>'s <code>CurrentCell</code> property to <code>Nothing</code> (or any cell outside of the current row) since I want to commit from within an event handler of a custom edit control created by a custom column, and I see an <code>System.InvalidOperationException</code> exception when setting <code>CurrentCell</code> there.</p> <p>In fact, it is a tiny button right to a combo box, i.e. I create a <code>DataGridViewComboBoxCell</code> descendant which is a <code>DataGridViewComboBoxColumn</code> descendant's edit control. My special ComboBox cell adds a tiny button which should commit the current row. Unfortunately, that button's <code>_Click</code> event handler cannot change <code>CurrentCell</code> since <code>DetachEditingControl</code> throws the exception then. </p> <p>Obviously, I must delay the <code>CurrentCell</code> re-assignment until the whole <code>_Click</code> event has been processed. Or what? How would I do that -- register a custom Windows message, <code>SendMessage</code> that one to me, and override the windows procedure of the form so it re-sets <code>CurrentCell</code> when this message is received? (Hello?)</p> <p><strong>There should be a rather easy way to let <code>DataGridView</code> commit all changes by firing the events that I handle to perform the datastore update, no?</strong></p> <p>I hope it is somewhat clear what I am talking about. I do not have a compact code example yet :(</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload