Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Where is the code behind Add button for Winform BindingNavigator Control?

Tags:

winforms

There is code for save button, but I can't see any code behind the Add button though the button works ?

So what would it be as I want to create my own not from scratch ?

Thanks.

like image 842
programmernovice Avatar asked Dec 23 '22 09:12

programmernovice


1 Answers

The way the add button wires up, is to the underlying type or BindingSource. Based on the behavior I saw yesterday, if the underlying list was bound to a type that had an empty constructor it was enabled, if not, the button was disabled. So it should be

this.bindingNavigator1.BindingSource.AddNew();
this.bindingNavigator1.BindingSource.MoveLast();

if you have something where you don't want the default constructor use something like this:

this.bindingNavigator1.BindingSource.Add(new T(1));
this.bindingNavigator1.BindingSource.MoveLast();

The save code would be as such:

If you are using a strongly typed dataset the code would be like

DataSet.AcceptChanges();

or if using tableAdapters

var myTableAdapter=new DataSet1TableAdapters.assetTableAdapter();
myTableAdapter.Update(DataSet);

You may not be getting many views on a holiday/weekend.

like image 95
Maslow Avatar answered May 22 '23 09:05

Maslow