disable option on delete bindingnavigator


David32 on Wed, 17 Oct 2012 16:27:57

I have a grid that is bound to a Binding Navigator in a windows form app. I want to give the user an option to not delete after clicking the delete button. I have the following code in the onclick event for the Delete button of the Navigator bar,

String m_answer = MessageBox.Show("Are You Sure You Want to Delete \n " + first_NameTextBox.Text + " " + last_NameTextBox, "Warning", MessageBoxButtons.OKCancel, MessageBoxIcon.Warning, MessageBoxDefaultButton.Button1).ToString(); if (m_answer == "OK") { Toggle_Controls(false); //This line just reenables other controls

} else { //Cancel Event }

but it's deleteing anyway. I assume the delete function is firing before this event is handled. Anyway how can I implement this?

Thanks in advance.


JSpeight on Wed, 17 Oct 2012 19:44:02

I think (not 100% sure) you need to set the ToolStripItem that is associated with the Delete function.

public ToolStripItem DeleteItem { get; set; }

in the example ToolStripItem represents the Delete button for the BindingSource.

When it has been set this property should generate the Click event handler for the Delete button. This event handler calls the RemoveCurrent method when the Delete button is clicked.

This property is null if it was not previously set.

The BindingNavigator control will disable the Delete button under the following run-time circumstances:

the BindingSource property is null 

 the Count property is 0,

or theAllowRemove property is false.