This tutorial will demonstrate the creation of a simple LightSwitch application which will be a simple customers application with a single table of customers.
Create a New LightSwitch Project
- Start up Visual Studio LightSwitch from Start > All Programs > Microsoft Visual Studio 2010 > Microsoft Visual Studio 2010.
- Select File > New Project and the New Project dialog box will appear.
- From the Installed Templates listing, select the LightSwitch. (Note that if you are using the full version of Visual Studio Professional with LightSwitch installed you will be shown more templates than just the LightSwitch templates).
- Select the LightSwitch Application (Visual Basic) template which we will use for this demo and enter a name for the project (in this case I have used lightswitchdemo)
- Once the application has been created you will be shown an option to either Create a New Table (if the app is being created with an all new database) or Attach to External Database if you need to use LightSwitch as a front-end to an existing database. For this tutorial we will select Create a New Table:
Before we proceed, note the structure of the LightSwitch project from the Solution Explorer in Visual Studio. There are three elements :
- Properties – which is main configuration settings for LightSwitch, such as whether the app will be deployed as as a browser app or a stand-alone desktop app.
- Data Sources – the data tables being used to data storage by the LightSwitch app.
- Screens – the front-end ‘screens’ or pages which the end user will use to interact with the application.
Creating a Data Table in LightSwitch
In this section of the tutorial we will create a table for storing the company’s customer data
- Click Create new Table from the screen shown above (alternatively you can right-click on Data Sources in the Solution Explorer and select Add Table).
- Enter the details for each field in the table entry form. In this demo of a customers data tables I have used the fields FirstName, LastName, Email and PhoneNumber. Set the data type for each field, the default type is String, but note the types of EmailAddress and PhoneNumber which have inbuilt validation (as we will see in later tutorials) and should be used whenever possible for these fields. Save the fields by click Control+S or the save icon in the Visual Studio toolbar. For this tutorial I have set all fields to Required, but note that you will often want to uncheck this requirement for some fields to make their input option.
- Change the table name to Customers by right-clicking on the table (currently named TableItem1) under Data Sources > ApplicationData , and then selecting Rename
Display Customer Data in an Editable Grid
In this final part of the tutorial we will create a simple one screen grid which the user will be able to view, edit and add customers to the LightSwitch application.