Deleting row from DataView (OT)

D

Derrick

Hello;

Sorry for being a little off topic. I've posted to the ADO.NET group as
well :)

Dealing with Winforms on 1.1 framework, VS.NET 2003.

I have a DataView (which is the Data Source for a DataGrid), and I want to
be able to delete rows only if specific columns contain specific values.
For example, one of the columns contains boolean values; if the value for
the row we are attempting to delete is true go ahead and delete it, but if
it's false cancel the delete.

I have a handler hooked to the DataTable.RowDeleting event (the DataTable is
obviously the source for my DataView), which supposedly fires before the row
is deleted. In there, I check my column conditions, but what I need to know
is what do I call to cancel the deletion? I've tried DataRow.RejectChanges,
DataRow.CancelEdit, and DataTable.RejectChanges to no avail - the row always
disappears from the DataGrid, so I assume the row is being deleted from the
view. I step through the event, so it is being triggered and my condition
checking is accurate.

I also tried doing stuff in the DataView.ListChanged

Thanks for your help;

Derrick
 
N

Nicholas Paldino [.NET/C# MVP]

Derrick,

Instead of allowing people to delete through the data view/data table,
why not create a wrapper for accessing the rows (or at least, performing
actions on the rows) which will not perform the delete in the first place.

Then, you route all the calls through that.

Also, have you tried throwing an exception? This might be the only way
to get the operation to cancel.

Hope this helps.
 

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