--- title: Add Load, Save, and Cancel Buttons to BindingNavigator Control description: Learn how to add Load, Save, and Cancel buttons to the Windows Forms BindingNavigator control. ms.date: "03/30/2017" dev_langs: - "csharp" - "vb" helpviewer_keywords: - "controls [Windows Forms], manipulating" - "BindingNavigator control [Windows Forms], adding buttons" ms.assetid: faa33042-186e-4bb2-8798-17ceb987ec62 --- # How to: Add Load, Save, and Cancel Buttons to the Windows Forms BindingNavigator Control The control is a special-purpose control that is intended for navigating and manipulating controls on your form that are bound to data. Because it's a control, the component can be easily modified to include additional or alternative commands for the user. In the following procedure, a control is bound to data, and the control that is added to the form is modified to include load, save, and cancel buttons. ## Add load, save, and cancel buttons to the BindingNavigator component 1. In Visual Studio, add a control to your form. 2. Bind it to a , which is bound to a data source. For this example, the is bound to a database. 3. After the dataset and table adapter are generated, drag a control to the form. 4. Set the control's property to the on the form that is bound to the controls. 5. Select the control. 6. Click the designer actions glyph (![Small black arrow](./media/designer-actions-glyph.gif)) so the **BindingNavigator Tasks** dialog appears and select **Edit Items**. The **Items Collection Editor** appears. 7. In the **Items Collection Editor**, complete the following: 1. Add a and three items by selecting the appropriate type of and clicking the **Add** button. 2. Set the property of the buttons to **LoadButton**, **SaveButton**, and **CancelButton**, respectively. 3. Set the property of the buttons to **Load**, **Save**, and **Cancel**. 4. Set the property for each of the buttons to **Text**. Alternatively, you can set this property to **Image** or **ImageAndText**, and set the image to be displayed in the property. 5. Click **OK** to close the dialog box. The buttons are added to the . 8. Right-click the form and choose **View Code**. 9. In the Code Editor, find the line of code that loads data into the table adapter. This code was generated when you set up the data binding in step 2. The code should be similar to the following: `TableAdapterName.Fill(DataSetName.TableName)`. It will most likely be in the form's event. 10. Create an event handler for the event of the **Load** you created earlier and move this data-loading code into it. Your code should now look similar to the following: ```vb Private Sub LoadButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles LoadButton.Click TableAdapterName.Fill(DataSetName.TableName) End Sub ``` ```csharp private void LoadButton_Click(System.Object sender, System.EventArgs e) { TableAdapterName.Fill(DataSetName.TableName); } ``` 11. Create an event handler for the event of the **Save** you created earlier and write code to update the data within the table the control is bound to. ```vb Private Sub SaveButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles SaveButton.Click TableAdapterName.Update(DataSetName.TableName) End Sub ``` ```csharp private void SaveButton_Click(System.Object sender, System.EventArgs e) { TableAdapterName.Update(DataSetName.TableName); } ``` > [!NOTE] > In some cases, the component already has a **Save** button, but no code has been generated by the Windows Forms Designer. In this case, you can place the preceding code in the event handler for that button, rather than creating an entirely new button on the . However, the button is disabled by default, so you must set the property of the button to `true` to have the button function correctly. 12. Create an event handler for the event of the **Cancel** you created earlier and write code to cancel any changes to the data record that is displayed. ```vb Private Sub CancelButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CancelButton.Click BindingSourceName.CancelEdit() End Sub ``` ```csharp private void CancelButton_Click(System.Object sender, System.EventArgs e) { BindingSourceName.CancelEdit(); } ``` > [!NOTE] > The method is scoped to the row of data. Save any changes you make while viewing that individual record before navigating to the next record. ## See also - - - - [BindingNavigator Control](bindingnavigator-control-windows-forms.md) - [BindingSource Component Overview](bindingsource-component-overview.md)