You are here
Home > Programming > LightSwitch Data – Fleshing Out Your Application

LightSwitch Data – Fleshing Out Your Application

Fallback Image

lightswitch data logoLightSwitch Data – If you have followed the previous two articles I wrote (Visual Studio LightSwitch – True Power Lies In Simplicity and Extending LightSwitch – Deeper Down The Rabbit Hole), you will by now know that our little application is becoming more sophisticated and feature rich.

I have to hasten to add, our application is becoming more feature rich without us having to do much work. It seems almost like stealing candy from a baby, and I almost feel guilty for getting so much satisfaction from creating with LightSwitch.

If by now you aren’t hooked on LightSwitch, I don’t know what will get you hooked. The more I play with LightSwitch, the more I love it. It is easy to see why there is such a large community behind this technology.

As I have mentioned before, it is the data that drives LightSwitch. The underlying data layer needs to be correct, so a basic understanding of databases is preferable. But the technology is also very forgiving. Give it a few hours time, and you will be quite fluent with it.

LightSwitch Data – Make Changes Effortlessly

Let us assume that you have started creating your application but you now need to add some additional fields to one of your existing tables. This could be as a result of a user request or that you simply forgot to add it in the first place. Changing the data will undoubtedly change the form. You might be apprehensive because you don’t want to break something by modifying the underlying tables. Well let me assure you, LightSwitch is very robust. Modifying tables and changing your screens is just as easy as the previous tasks we performed.

Start by going to your Solution Explorer pane in Visual Studio again.

select member table

Select the Members table.

add additional fields

For arguments sake, let us just add some additional detail here with regards to the next of kin.

select member screen

Next, you need to select the Members screen to add the additional fields.

add additional form fields

This time we are going to add these fields to our screen a little differently.

drag additional field to form

In the left field list, select the ‘Father’ field and drag it under your ‘Group’ field. You will see a blue line marking the position where your additional field will be added.

additional field added to form

After you have added the ‘Father’ field, you can go ahead and add the other additional fields previously added to your table.

fields on form visible

Save the LightSwitch solution in Visual Studio and run your app. After a few seconds, your form will be displayed and you will see the additional fields added to your application. This was easy enough. In no time, we were able to modify the underlying table fields and directly influence the screen design by associating the data to the screen via text controls. But let us imagine that another additional field is required that needs to store additional data. This time a single line text entry will not work.

additional info

Go ahead and modify your Members table and add a field called ‘Additional Info’. Associate this field with your members screen as we did in the previous steps above.

additional info properties

Take note of the Properties section to the right of the Customization Mode screen for Members when you select the Additional Info field.

change to multiline

Have a look under the Sizing group, towards the bottom (you might need to scroll down) there will be a ‘Lines’ radio button. Select this and change the default 1 line to 10 lines.

additional info multiline

Save these changes in the designer and return to your Windows application. You will now see that the Additional Info field is now in actual fact a text area. These changes were once again done with absolute minimal effort and allowed us to change the underlying data that drives the form. Let us now go and paste a bunch of text into our Additional Info field.

validation error

Whoa, stop the presses. Adding a whole lot of text to our Additional Info field caused a validation error. Luckily LightSwitch allows us to ‘Click here for more details’ to get more information on the error being reported.

validation error details

Doing this allows us to see that the Additional Info field only allows us to add a maximum of 255 characters. Well this is a fine how do you do. Once again, LightSwitch makes this quite easy to change. Stop your application from running and return to the Members table.

change field length

In the properties of the Members table for the Additional Info field (near the bottom) you will see that the field length is defined as 255.

field length changed

Change this value to a larger value. I made mine a healthy 1500 characters.

additional info field length changed

If you run your application again, you will notice that you can now easily add and save the large amount of text you added previously into the Additional Info field.

LightSwitch has once again come through for us. We are programmers! Defenders of the Lazy and don’t-reinvent-the-wheel type personalities. With minimal effort we have once again made significant changes to our application. I know that I am steam rolling through many of these features, but there are just so many that lie ahead, just waiting to be discovered. Go ahead and open a whole new world for yourself. Explore LightSwitch. You can thank me later.

Image Reference

Dirk Strauss
Dirk is a Software Developer from South Africa. He loves all things Technology and is slightly addicted to Jimi Hendrix. Apart from writing code, he also enjoys authoring books and articles. "I love sharing knowledge and connecting with people from around the world. It's the diversity that makes life so beautiful." Dirk feels very strongly that pizza is simply not complete without Tabasco, that you can never have too much garlic, and that cooking the perfect steak is an art he has almost mastered.
https://dirkstrauss.com

Similar Articles

Top