How to stop deletion in data grid

fshrago

Member
Joined
Sep 6, 2006
Messages
11
Programming Experience
5-10
Using vb.net 2.0 and visual studio 2005

I have a datagrid which is bound to a Bindingsource and has a connect binding neavigator.

I want be able to cancel the deletiong based on a dialog result. so far I have:

VB.NET:
[SIZE=2]
[/SIZE][SIZE=2][COLOR=#0000ff]Private[/COLOR][/SIZE][SIZE=2] [/SIZE][SIZE=2][COLOR=#0000ff]Sub[/COLOR][/SIZE][SIZE=2] BindingNavigatorDeleteItem_Click([/SIZE][SIZE=2][COLOR=#0000ff]ByVal[/COLOR][/SIZE][SIZE=2] sender [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2] System.Object, [/SIZE][SIZE=2][COLOR=#0000ff]ByVal[/COLOR][/SIZE][SIZE=2] e [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2] System.EventArgs) [/SIZE][SIZE=2][COLOR=#0000ff]Handles[/COLOR][/SIZE][SIZE=2] BindingNavigatorDeleteItem.Click
[/SIZE][SIZE=2][COLOR=#0000ff]If[/COLOR][/SIZE][SIZE=2] MessageBox.Show([/SIZE][SIZE=2][COLOR=#800000]"Are you sure"[/COLOR][/SIZE][SIZE=2], [/SIZE][SIZE=2][COLOR=#800000]"WSO"[/COLOR][/SIZE][SIZE=2], MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button2) = Windows.Forms.DialogResult.Yes [/SIZE][SIZE=2][COLOR=#0000ff]Then
[/COLOR][/SIZE][SIZE=2]daCategories.Update(dsWSO.Categories)
[/SIZE][SIZE=2][COLOR=#0000ff]Else
[/COLOR][/SIZE][SIZE=2][/SIZE][SIZE=2][COLOR=#008000]'dont save and reset datagrid
[/COLOR][/SIZE][SIZE=2][/SIZE][SIZE=2][COLOR=#0000ff]End[/COLOR][/SIZE][SIZE=2] [/SIZE][SIZE=2][COLOR=#0000ff]If
[/COLOR][/SIZE][SIZE=2][/SIZE][SIZE=2][COLOR=#0000ff]End[/COLOR][/SIZE][SIZE=2] [/SIZE][SIZE=2][COLOR=#0000ff]Sub
[/COLOR][/SIZE]

The problem is, I do not know how to reset the datagrid. If you click the delete icon, the msgbox comes up by the row is still deleted from the grid (though the changes are saved).
 
I don't see either datatable, or datarow as a property or method of the datagrid?

Do you have some example code you could show me?
 
No, your TableAdaptor has retrieved information form some kind of datasource MS Access, SQL Server etc... It then , in most cases, populates a datatable with the information you have specified. So if it is a datatable, it will probably be inside a dataset. Any of this making sense?
 
This is also something I'm looking for. I tried what you said and derived this code, which looks like it should be correct, but does not work:

Me.LogBookDataSet.tblLogFile.DataSet.RejectChanges()

Also Tried these to variations with no success:

Me.LogBookDataSet.tblLogFile.RejectChanges()
Me.LogBookDataSet.RejectChanges()
 
rejectchange only stop the deletion from dataset, not from UI. i also want to know how to keep the same record in UI.
 
One work around I thought of is possibly saving the data row(s), then if they click no, insert them back in.
 
Back
Top