if statements for delete

rjhe22

Well-known member
Joined
May 22, 2008
Messages
88
Programming Experience
Beginner
hi im a tryin to figure out how i can get theis to work. when i press the x button i want it to either let me delete the field if its empty or tell me that i cant because it has something in it. any help would be great. i no its not hard but for some reason just cant think of it.



Code:
Private Sub BindingNavigatorDeleteItem1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BindingNavigatorDeleteItem1.Click

' If Me.grdBankNotes.Columns null Then
'
Else
MessageBox.Show("Can not delete a bank account that has notes attached to it")
End If
End Sub
 
First up, you need to get rid of that event handler. You cannot handle that event because, no matter what code you put in there, the record will still be deleted.

Next, you need to open the Properties window for the BindingNavigator and clear the DeleteItem property. That's not going to remove that button from the BindingNavigator. It just means that that button is no longer going to automatically delete anything.

Finally, you need to double-click the Delete button to create a Click event handler for that button. Now you are completely in control of what happens when that button is clicked. You can get the current record as a DataGridView from the BindingSource's Current property. You can then test any field of that record you like to decide what to do. If you decide you want to delete then you call the RemoveCurrent method of the BindingSource.
 
can anyone tell me why this wont work

Dim blnOK As Boolean = True


If Me.grdBankNotes.Rows.Count > 0 Then
blnOK = False
MessageBox.Show("Can not delete a bank account that has notes attached to it")
Else
blnOK = True
End If
 

Latest posts

Back
Top