Save of BindingNavigator

besmart2000

Active member
Joined
Feb 18, 2007
Messages
25
Programming Experience
1-3
Hi all
I created baseForm that contain a BindingNavigator only
I want to write a common SAVE Click event to be shared for all forms that inherit from BaseForm.

Commonly, the generated code is like:

Private Sub CategoriesBindingNavigatorSaveItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CategoriesBindingNavigatorSaveItem.Click
Me.Validate()
Me.CategoriesBindingSource.EndEdit()
Me.CategoriesTableAdapter.Update(Me.NorthwindDataSet.Categories)

End Sub

The problem is
CategoriesTableAdapter which is generated for every form and it is System.ComponentModel.Component and table dependent.

I want to cenenteralize the Save Code in the BaseForm.
How Can I implement The Save Code using BindingSource Control which can be passed as a parameter, without using CategoriesTableAdapter (i.e to be Table independent)

thanks

 
BindingNav doesnt actually know anything about the bindingsource - its simply something the designer uses to write code behind the scenes.

Without creating any inherited members, youll need to look through the controls collection on the form and find one you think to be a tableadapter and use reflection to call update.

I actually favour the route of creating also a base TableAdapter with a Must Override GenericSave(dataset) sub.. Then write one line of code for each of your tableadapters that simply calls the local Update() and passes the supplied dataset..

Thing is, i'm not sure why you want to inherit this particular aspect of the form - why not have each form have its own bind nav? The IDE creates the code for you, so its not even like you have to type something?
 
Hi Cjard
I added extra services to the BindingNavigator in the BaseForm like ConfirmDeletion service , Cancle Edit, that is why i want to add also save service in the BaseForm.

Wizard do not create save code in case of inheriting Bindingnavigator, and i should write it.
Please , can you help me with sample of code to express your idea.
Best regards,
 
Must the save functionality be incorporated in this way too, though? Would it be better to just leave save delegated? (It already is, if you simply put the click handler in the child form).
If you like, you can create an abstract method Save() in the baseform, and all the child forms must override it before the project will compile - each can implement the save

VB.NET:
Class BaseForm
  XYZBindingNavigator_SaveItem_Click()
    SaveDetails()
  
  Public MustInherit SaveDetails()
 
Back
Top