Hi,
[quoted text, click to view] "Paul Say" <saywin@tpg.com.au> wrote in message
news:eHP6h9ORHHA.2252@TK2MSFTNGP02.phx.gbl...
>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
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] >
> Thanks
>
> Paul
>