the proper way to detect changes to current row before moving to next row

G

GS

How do I properly detect row change before allowing moving to next row?

I tried using RowLeave .

here is brief descript of the form setup.

I have
ieStringTmpDataSetwith regex table connected to a SQL mdf.,
on the form I have a regexDataGridView for the table regex for
navigation and viewing purpose only
also the associated navigator, detail view controls bounded with the
same binding source for editing.

so the current row of the regexDataGridView is shown on the detail view
controls

here is the code for the Rowleave Event
DataRow[] dr = ieStringTmpDataSet.Regex.Select("", "",
DataViewRowState.ModifiedCurrent);

int irowsChgd = dr.GetUpperBound(0) + 1;
if (regexDataGridView.IsCurrentRowDirty | irowsChgd > 0)
{
DialogResult dlgReslt = MessageBox.Show("Save Changes?",
this.Text + " - The row has unsaved changes",
MessageBoxButtons.YesNo);
if (dlgReslt == DialogResult.Yes)
{
regexBindingNavigatorSaveItem.PerformClick();
setStatus("Saved change to regex " +
regexNameTextBox.Text);
}
else
{ //' problem with cancelling change, cancel edit does not
work
regexDataGridView.CancelEdit();
ieStringTmpDataSet.RejectChanges();
// causes exception later:
ieStringTmpDataSet.Regex.Reset();
setStatus("Change to regex is still pending for " +
irowsChgd + " rows. Please reload to forget change");
}
}
else if (statusLabel.Text != "Ready") setStatus("Ready");

Problem: the event tend to delay prompting until 2nd row leave after a row
has been modified


your help to show me the propeway to detect modifcation is much appreciated.
thank you for your time and advice

Btw regexDataGridView.IsCurrentRowDirty always returns false
 
G

Greg

How do I properly detect row change before allowing moving to next row?

I tried using RowLeave .

here is brief descript of the form setup.

 I have
    ieStringTmpDataSetwith regex table connected to a SQL mdf.,
    on the form I have a regexDataGridView for the table regex for
navigation and viewing purpose only
        also the associated navigator, detail view controls bounded with the
same binding source for editing.

so the current row of the regexDataGridView is shown on the detail view
controls

here is the code for the Rowleave Event
    DataRow[] dr = ieStringTmpDataSet.Regex.Select("", "",
         DataViewRowState.ModifiedCurrent);

            int irowsChgd = dr.GetUpperBound(0) + 1;
            if (regexDataGridView.IsCurrentRowDirty | irowsChgd > 0)
            {
                DialogResult dlgReslt = MessageBox.Show("Save Changes?",
                    this.Text + " - The row has unsaved changes",
MessageBoxButtons.YesNo);
                if (dlgReslt == DialogResult.Yes)
                {
                    regexBindingNavigatorSaveItem.PerformClick();
                    setStatus("Saved change to regex "+
regexNameTextBox.Text);
                }
                else
                {   //' problem with cancelling change, cancel edit does not
work
                    regexDataGridView.CancelEdit();
                    ieStringTmpDataSet.RejectChanges();
                    // causes exception later:
ieStringTmpDataSet.Regex.Reset();
                    setStatus("Change to regex is still pending for " +
irowsChgd + " rows. Please reload to forget change");
                }
            }
            else if (statusLabel.Text != "Ready") setStatus("Ready");

Problem: the event tend to delay prompting until 2nd row leave  after a row
has been modified

your help to show me the propeway to detect modifcation is much appreciated.
thank you for your time and advice

Btw regexDataGridView.IsCurrentRowDirty always returns false

Try using the RowValidating event. Inside the
DataGridViewCellCancelEventArgs is the Cancel property for this Row.
Greg
 
G

GS

uh...., the event seems to be called regardless if the are changes. just
change to a different row, will trigger it to fire until one replies yes
unless I put in a test query for dirty row

then I will face the same problem of missing the prompt on first row change
after a row is modified

How do I properly detect row change before allowing moving to next row?

I tried using RowLeave .

here is brief descript of the form setup.

I have
ieStringTmpDataSetwith regex table connected to a SQL mdf.,
on the form I have a regexDataGridView for the table regex for
navigation and viewing purpose only
also the associated navigator, detail view controls bounded with the
same binding source for editing.

so the current row of the regexDataGridView is shown on the detail view
controls

here is the code for the Rowleave Event
DataRow[] dr = ieStringTmpDataSet.Regex.Select("", "",
DataViewRowState.ModifiedCurrent);

int irowsChgd = dr.GetUpperBound(0) + 1;
if (regexDataGridView.IsCurrentRowDirty | irowsChgd > 0)
{
DialogResult dlgReslt = MessageBox.Show("Save Changes?",
this.Text + " - The row has unsaved changes",
MessageBoxButtons.YesNo);
if (dlgReslt == DialogResult.Yes)
{
regexBindingNavigatorSaveItem.PerformClick();
setStatus("Saved change to regex " +
regexNameTextBox.Text);
}
else
{ //' problem with cancelling change, cancel edit does not
work
regexDataGridView.CancelEdit();
ieStringTmpDataSet.RejectChanges();
// causes exception later:
ieStringTmpDataSet.Regex.Reset();
setStatus("Change to regex is still pending for " +
irowsChgd + " rows. Please reload to forget change");
}
}
else if (statusLabel.Text != "Ready") setStatus("Ready");

Problem: the event tend to delay prompting until 2nd row leave after a row
has been modified

your help to show me the propeway to detect modifcation is much appreciated.
thank you for your time and advice

Btw regexDataGridView.IsCurrentRowDirty always returns false

Try using the RowValidating event. Inside the
DataGridViewCellCancelEventArgs is the Cancel property for this Row.
Greg
 
Top