Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

delete datagridview row without deleting from database

Status
Not open for further replies.

EDB2

MIS
Sep 11, 2002
36
US
I have a datagridview in a windows application which is bound to an underlying database via a bindingsource/tableadapter. Is there a simple way to delete a row from a datagridview without deleteing it from the underlying database?

The user is processing data from the grid, and I want to give them the option of removing a record from the upload without actually getting rid of it (so they can correct and upload the remaining records at some other time).
 
Just hide the row, then only process the visible rows.

-Sometimes the answer to your question is the hack that works
 
Any changes to the data are not written to the database until the TableAdapter's .Update method is called. The .Update method only saves rows that have a DataRowState of Added, Deleted or Modified. You can remove the unwanted rows then call the TableAdapter's .AcceptChanges method, which sets the DataRowState of all rows to Unchanged. This will prevent them from being deleted in the database when .Update is called. Note that if there are any changes you want to save to the database, be sure to save them (via .Update) before you call AcceptChanges, or the edits will be lost and *not* saved to the database.



I used to rock and roll every night and party every day. Then it was every other day. Now I'm lucky if I can find 30 minutes a week in which to get funky. - Homer Simpson

Arrrr, mateys! Ye needs ta be preparin' yerselves fer Talk Like a Pirate Day!
 
Both great ideas, thank you! I chose the latter, and had to call 'acceptChanges' on the dataset rather than the tableAdaptor (there was no such method for the adaptor), but it worked like a charm.

Thanks so much!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top