G
Guest
I have a question about these events that I hope someone could help me with.
I have a DataGrid bound to a DataSet. The grid's datasource is a DataView
and deletes are allowed.
I have added a Event Handler for OnRowDeleting.
What I want to do, is to only allow deletes to occur for newly added records
(before DataSet.Update is run). I want to cancel deletes for existing
records.
The code for OnRowDeleting is:
Private Sub OnRowDeleting(ByVal sender As Object, ByVal e As
DataRowChangeEventArgs)
'=============================================================
' This event fires when a row is being deleted
|
'=============================================================
Try
If e.Row.RowState <> DataRowState.Added Then
Throw (New DeleteAgencyException("Cannot Delete an Existing
Row"))
End If
Catch ex As DeleteAgencyException
MessageBox.Show(ex.Message, "Delete Agency")
e.Row.RejectChanges()
End Try
End Sub
What happens is my Exception is captured and the message displayed, but the
row is still deleted. The RejectChanges doesn't seem to actually reject the
changes. I tried CancelEdit and got the same results. How can I cancel the
changes?
Thanks
John
I have a DataGrid bound to a DataSet. The grid's datasource is a DataView
and deletes are allowed.
I have added a Event Handler for OnRowDeleting.
What I want to do, is to only allow deletes to occur for newly added records
(before DataSet.Update is run). I want to cancel deletes for existing
records.
The code for OnRowDeleting is:
Private Sub OnRowDeleting(ByVal sender As Object, ByVal e As
DataRowChangeEventArgs)
'=============================================================
' This event fires when a row is being deleted
|
'=============================================================
Try
If e.Row.RowState <> DataRowState.Added Then
Throw (New DeleteAgencyException("Cannot Delete an Existing
Row"))
End If
Catch ex As DeleteAgencyException
MessageBox.Show(ex.Message, "Delete Agency")
e.Row.RejectChanges()
End Try
End Sub
What happens is my Exception is captured and the message displayed, but the
row is still deleted. The RejectChanges doesn't seem to actually reject the
changes. I tried CancelEdit and got the same results. How can I cancel the
changes?
Thanks
John