Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Windows Forms / WinForm Data Binding / January 2007

Tip: Looking for answers? Try searching our database.

BindingNavigator How do i disable the delete on a per record basis

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Paul Say - 31 Jan 2007 04:22 GMT
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 - 31 Jan 2007 20:53 GMT
Hi,

>I have a BindingNavigator, BindingSource (Custom Object) and a
>DataGridView.
[quoted text clipped - 4 lines]
>
> 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

> Thanks
>
> Paul

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.