|
dev
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
RowNotInTableException - HelpI 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 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 Show quote "Stan" <S***@discussions.microsoft.com> wrote in message news:35503966-D2B2-4252-82BE-B3665B2D9110@microsoft.com... > 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 >
Other interesting topics
|
|||||||||||||||||||||||