|
dev
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
Gridview deletion problemfrom the Data Sources tab, and dragged the Product table from the Data Source tab to the form's designer surface. This created a dataset, bindingsource, tableadapter and bindingnavigator. I placed the following code in the click event of the delete button on the bindingnavigator: Me.Validate() Me.ProductBindingSource.EndEdit() Me.ProductTableAdapter.Update(Me.AdventureWorksDataSet.Product) When running the app, I select a row and click the delete button on the navigator. It disappears. However, when I exit the app and re-enter, the row is still there. As another test, if I select the row again, and click the delete button, and click it once more, the row is actually deleted from the database. In debug I place a stop after the Validate method above. The underlying dataset shows false for HasChanges after the first click of the delete button and the selected row shows Unchanged for its RowState. However, after the 2nd click of the delete button, the dataset shows true for HasChanges and Deleted for the RowState associated with the row. What is wrong with my code? Thanks Wen Yuan,
In working with the code further, I need some advice on an appropriate approach. Given that the following code works: Me.ProductBindingSource.RemoveCurrent () Me.Validate() Me.ProductBindingSource.EndEdit() Me.ProductTableAdapter.Update(Me.AdventureWorksDataSet.Product) I can get an error from the update method on a referential constraint - the row is used somewhere else and cannot be deleted. I can wrap the update in a try-catch block so that I retain control over the process, but the item has already been removed from the grid in the first statement, the RemoveCurrent method. The user sees the error message (I use an error provider in the try-catch block) that it can't be deleted, but the item is visually deleted. What approach can I use to avoid this? Thanks, Flomo On Thu, 18 Jan 2007 08:59:22 -0800, Flomo Togba Kwele <flomo@community.nospam> wrote: Show quote >I created a form, a datasource (Product table from AdventureWorks) >from the Data Sources tab, and dragged the Product table from the Data >Source tab to the form's designer surface. > >This created a dataset, bindingsource, tableadapter and >bindingnavigator. > >I placed the following code in the click event of the delete button on >the bindingnavigator: > > Me.Validate() > Me.ProductBindingSource.EndEdit() > Me.ProductTableAdapter.Update(Me.AdventureWorksDataSet.Product) > >When running the app, I select a row and click the delete button on >the navigator. It disappears. However, when I exit the app and >re-enter, the row is still there. > >As another test, if I select the row again, and click the delete >button, and click it once more, the row is actually deleted from the >database. > >In debug I place a stop after the Validate method above. The >underlying dataset shows false for HasChanges after the first click of >the delete button and the selected row shows Unchanged for its >RowState. > >However, after the 2nd click of the delete button, the dataset shows >true for HasChanges and Deleted for the RowState associated with the >row. > >What is wrong with my code? > >Thanks Hi Flomo,
Thanks for you reply. Each bindingSource is related to a datatable/dataset. After bindingsource.removecurrent() method has been called, the row in the datatable will be flagged as "deleted". If we want to cancel this transact, we can call rejectChanges() method. For example; CType([Me.BindingSource.DataSource], System.Data.DataSet).RejectChanges() Could you add this statement into try-catch block to check whether or not this method works for you. I'm very glad to work with you. Please reply if you have any further problem or concerns on this. Hope this helps. Have a great day! Wen Yuan And if it's not a dataset but a custom object?
On Thu, 25 Jan 2007 07:30:03 GMT, v-wyw***@online.microsoft.com (WenYuan Wang) wrote: Show quote >Hi Flomo, >Thanks for you reply. > >Each bindingSource is related to a datatable/dataset. After >bindingsource.removecurrent() method has been called, the row in the >datatable will be flagged as "deleted". If we want to cancel this transact, >we can call rejectChanges() method. > >For example; CType([Me.BindingSource.DataSource], >System.Data.DataSet).RejectChanges() > >Could you add this statement into try-catch block to check whether or not >this method works for you. >I'm very glad to work with you. Please reply if you have any further >problem or concerns on this. > >Hope this helps. >Have a great day! >Wen Yuan Hi Flomo,
I Just want to check if the issue has been resolved? If it still persists, please don't hesitate to update here. We'll go on to assist you on it. Thanks. Best Regards, Wen Yuan Hi,
I'm wondering why there's no somethings like ItemRemoved event? ""WenYuan Wang"" wrote: Show quote > Hi Flomo, > > I Just want to check if the issue has been resolved? If it still persists, > please don't hesitate to update here. > We'll go on to assist you on it. Thanks. > > Best Regards, > Wen Yuan > > |
|||||||||||||||||||||||