How about cloning the DeleteButton?
using System;
using System.Data;
using System.Drawing;
using System.Windows.Forms;
public partial class Form1 : Form
{
private readonly DataGridView dataGridView;
private readonly BindingSource bindingSource;
private readonly BindingNavigator bindingNavigator;
private readonly DataTable dataTable;
public Form1() {
InitializeComponent();
dataTable = new DataTable();
dataTable.Columns.Add("ID", typeof(int));
dataTable.Columns.Add("Name", typeof(string));
dataTable.Rows.Add(1, "Alice");
dataTable.Rows.Add(2, "Bob");
dataTable.Rows.Add(3, "Charlie");
bindingSource = new BindingSource {
DataSource = dataTable
};
dataGridView = new DataGridView {
Dock = DockStyle.Fill,
DataSource = bindingSource
};
bindingNavigator = new BindingNavigator(true) {
Dock = DockStyle.Top,
BindingSource = bindingSource
};
using (ToolStripButton deleteButton = (ToolStripButton)bindingNavigator.DeleteItem) {
bindingNavigator.Items.Remove(deleteButton);
ToolStripButton newDeleteItem = CloneToolStripButton(deleteButton);
newDeleteItem.Click += DeleteButton_Click;
bindingNavigator.Items.Add(newDeleteItem);
}
Controls.Add(dataGridView);
Controls.Add(bindingNavigator);
}
static ToolStripButton CloneToolStripButton(ToolStripButton oldButton) {
var newButton = new ToolStripButton {
Name = oldButton.Name,
Text = oldButton.Text,
Image = new Bitmap(oldButton.Image),
RightToLeftAutoMirrorImage = oldButton.RightToLeftAutoMirrorImage,
DisplayStyle = oldButton.DisplayStyle
};
return newButton;
}
private void DeleteButton_Click(object sender, EventArgs e) {
if (bindingNavigator.Validate()) {
var result = MessageBox.Show("Do you want to delete it?",
"Question",
MessageBoxButtons.YesNo);
if (result == DialogResult.Yes) {
bindingSource.RemoveCurrent();
bindingNavigator.Refresh();
}
}
}
}