Note that there are some explanatory texts on larger screens.

plurals
  1. POdatagridview rowvalidating cancel
    primarykey
    data
    text
    <p>I've seen several posts here and on other sites that are similar to my question/problem, but have never really seen anything directly on-target and with a good answer (if I missed one in my search, please point me to it!). Please forgive me if this is long, but I want to give as complete/accurate a descriptions as I can... Thanks in advance for your help!!</p> <p>I have a Windows form with side-by-side datagridviews (dgdApplications &amp; dgdEligibleFiles). dgdApplications is set for FullRowSelect and validation (CausesVailidation = true). dgdEligibleFiles contains a list of files &amp; file info, and a checkbox column - if a row is checked, the file it represents is "assigned" to the selected row in dgdApplications (a row/application in dgdApplications may have many files assigned to it). If a user has altered his assignments in dgdEligibleFiles (checked/unchecked one/more rows) without clicking the Save button at form-bottom, and then clicks another row in dgdApplications, I currently use dgdApplications_RowValidating to pop a messagebox and verify that the user wants to proceed to the newly-selected application/row without saving changes. If the "No" button is clicked, I call e.Cancel to stay in the original row. If "Yes", I want to proceed with dgdApplications_MouseClick on the new row, which will do the following: clear the checkboxes in dgdEligibleFiles, retrieve the list of files for the newly selected app in dgdApplications, and update checked/selected values in the underlying list bound to dgdEligibleFiles (followed by dgdEligibleFiles.Refresh()).</p> <p>My problem: When the messagebox is displayed in dgdApplications.RowValidating and the user chooses "Yes" to continue (abandoning changes in dgdEligibleFiles and going to the new row in dgdApplications), dgdApplications_MouseClick does not get executed and nothing changes in dgdEligbleFiles. How can I get dgdApplications_MouseClick to execute? </p> <pre><code>void dgdApplications_RowValidating(object sender, DataGridViewCellCancelEventArgs e) { if (assgnmtChgd &amp;&amp; (MessageBox.Show("You will lose unsaved changes - continue?", "", MessageBoxButtons.YesNo) == DialogResult.No)) { e.Cancel = true; return; } } /// &lt;summary&gt; /// Handles the selection of an application when it's datagridview row is clicked /// &lt;/summary&gt; /// &lt;param name="sender"&gt;&lt;/param&gt; /// &lt;param name="e"&gt;&lt;/param&gt; private void dgdApplications_MouseClick(object sender, MouseEventArgs e) { // Reset the DisplayAssignedOnly checkbox so all dgdEligibleFiles rows will be unhidden and displayed chkDispAssgndOnly.CheckState = CheckState.Unchecked; ClearFilesGrid(); dgdApplications.CurrentRow.Selected = true; currentAppRowID = dgdApplications.CurrentRow.Index; currentAppRecID = (int)dgdApplications.CurrentRow.Cells["appIDColumn"].Value; dgdEligibleFiles.ClearSelection(); dgdEligibleFiles.CurrentCell = null; MatchAssignedFiles(currentAppRecID); dgdEligibleFiles.Refresh(); //Set the indicator showing that no assignments have been changed assgnmtChgd = false; } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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