Add button in Visual Studio 2011 LightSwitch


Introduction

As you know that add button is used to add new data in the database. There is + sign to add new data in Visual Studio LightSwitch . If you want to add new data using custom button in the LightSwitch, it is possible.

Step by step solution

Step 1: Open Visual Studio LightSwitch->File->New->Project->Create new table.

image1.gif

Step 2: Now we will make a table like as Employee.

Image2.gif

Step 3: Right click on screen->Add new screen.

image3.gif

Step 4: Select Editable grid screen->Select screen data (Employee)->Ok.

image4.gif

Step 5: Run application (Press F5)->Click + sign ->Fill data->Ok->Save.

image5.gif

Step 6: Design screen->Command Bar->Add->New button->Change display name (AddEmployee)->Save.

image6.gif

Step 7: Stop debugging->Add screen->Select new data screen->Select screen data (Employee)->Ok.

image8.gif

Step 8: Go to properties of Editable grid screen->Change method name (AddEmployee)->Click edit execute code>Write the below code.

image7.gif

Code :

using System;
using System.Linq;
using System.IO;
using System.IO.IsolatedStorage;
using System.Collections.Generic;
using Microsoft.LightSwitch;
using Microsoft.LightSwitch.Framework.Client;
using Microsoft.LightSwitch.Presentation;
using Microsoft.LightSwitch.Presentation.Extensions;
namespace LightSwitchApplication
{
    public partial class EditableEmployeesGrid
    {
        partial void ADDEmployee_Execute()
        {
            this.Application.ShowCreateNewEmployee();
 
        }
    }

}

Step 9: Run application (Press F5)->Click AddEmployee button.

image9.gif

Step 10: Fill data->Save.

image10.gif

Step 11: Refresh.Here you will see new data save in the editable grid screen.

image11.gif

Summary

So you can use custom button as add in the LightSwitch Appliocation.

Up Next
    Ebook Download
    View all
    Learn
    View all