Groups | Blog | Home
all groups > dotnet windows forms databinding > january 2007 >

dotnet windows forms databinding : BindingNavigator How do i disable the delete on a per record basis


Paul Say
1/31/2007 2:22:31 PM
I have a BindingNavigator, BindingSource (Custom Object) and a DataGridView.

What i want to do is disable the delete button on the BindingNavigator based
on the value of a particular field within the selected row of the
DataGridView

Any ideas appreciated

Thanks

Paul

Bart Mermuys
1/31/2007 8:53:42 PM
Hi,

[quoted text, click to view]

Try something like this:

- Select the BindingNavigator and use the properties window to set
DeleteItem to (none).

- Double click on the delete button and add this code:

private void bindingNavigatorDeleteItem_Click(object sender, EventArgs e)
{
// cancel any pending new row
// (only has effect for ADO.NET or Custom Objects with IEditableObject)
int count = someBindingSource.Count;
someBindingSource.CancelEdit();
someBindingSource.ResetBindings(false);

// if no pending new row was removed, remove current row
if (someBindingSource.Count == count)
someBindingSource.RemoveCurrent();
}

- Add a CurrentChanged or CurrentItemChanged to the relevant BindingSource:

private void someBindingSource_CurrentChanged(object sender, EventArgs e)
{
CustomObject obj = (CustomObject)someBindingSource.Current;

// warning, in VB.NET use AndAlso not And
if (someBindingSource.Count > 0 && obj.SomeProp!=SomeCondition)
bindingNavigatorDeleteItem.Enabled = true;
else
bindingNavigatorDeleteItem.Enabled = false;
}

HTH,
Greetings

[quoted text, click to view]

AddThis Social Bookmark Button