RowNotInTableException - Help

G

Guest

I've written code that uses a DataGrid to display the data in a table. When
I am adding a new row to the table I've hooked into the ColumnChanged event
to verify that the data entered is correct. With a detached(new) row I get
this error when I have to reject the changes the user entered in the grid.

An unhandled exception of type 'System.Data.RowNotInTableException' occurred
in system.windows.forms.dll

Additional information: This row has been removed from a table and does not
have any data. BeginEdit() will allow creation of new data in this row.

Here is the function:

private void OnColumnChanged(object sender,DataColumnChangeEventArgs e) {
if (e.Column.ColumnName.ToLower().Equals("ety_id")) {
if (!m_etyId.Equals(e.Row[e.Column.ColumnName].ToString())) {
MessageBox.Show("Ety Id Entered is not Valid. Row will be reset","12b1
Processing");
try {
if (e.Row.RowState != DataRowState.Detached)
e.Row.RejectChanges();
else {
e.Row.BeginEdit();
e.Row.RejectChanges();
e.Row.EndEdit();
}
}
catch (Exception e1) {
System.Diagnostics.Debug.WriteLine(e1.ToString());
}
return;
}
}

Any help out there that would tell me how to reset the data in the grid? In
other words the user has entered lousy data and I want it to go bye bye.

Thanks

Stan
 
J

Jamie Bissett

Try hooking up to the CellValidating event whith the following psudeo logic:

<Data> Ok ? e.Cancel = false : e.Cancel = true;

This will set the e.Cancel in the EventArgs to either reject (stay in the
colomn in edit mode) or accept the changes dependant upon you're validation
test.

Jamie
 

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