[Last Call] Learn how to a build a cloud-first strategyRegister Now


Add detail records in same order as list

Posted on 2012-08-13
Medium Priority
Last Modified: 2012-10-16
I'm using LightSwitch and I've created a screen with a random list of 10 employees on the left and detail records on the right.  I'm able to select any employee and update the detail information.  What I want is to be able to...
Force the user to select an employee, and add a detail record, in the same order as the list

I think it would be easier to do this if I only showed one employee at a time but the user needs to be able to see the whole list.

Any suggestions?
Question by:BobRosas
  • 3
  • 2

Accepted Solution

Jean Marie Geeraerts earned 2000 total points
ID: 38353440
Let me see if I understood your question correctly:
You have created a list/detail screen, where you have the list of employees on the left and when you select an employee from the list the details for this employee are shown on the right.
Now you would like to have the user iterate through the list on the left and fill out all the details per employee.

So you probably have a data source like "Employees" on the screen that represents the list, and on the right you have "Employees.SelectedItem" bound to the details part.

One thing you could do to automatically select the next employee for which not all details are entered, is to write code in the Activated and Saved event of your screen that looks up the first employee from the list where not all required details are entered and then selects this record in the list.

To simplify this, you could add a computed property on the Employee table "IsCompleted" that returns true if all fields are entered and false if at least one field is left empty.

An example:
You have the table Employees with the following properties:
- LastName
- FirstName
- EmployeeNumber
- Phone
- Email
Computed property:
- IsCompleted

Code for IsCompleted:
       Private Sub IsCompleted_Compute(ByRef result As Boolean)
            result = Not String.IsNullOrEmpty(LastName) _
                 And Not String.IsNullOrEmpty(FirstName) _
                 And Not String.IsNullOrEmpty(EmployeeNumber) _
                 And Not String.IsNullOrEmpty(Phone) _
                 And Not String.IsNullOrEmpty(Email)
        End Sub

Open in new window

Then you create a ListDetail screen, based on Employees: EmployeesListDetail

Here I have the following code:
    Public Class EmployeesListDetail

        Private Sub EmployeesListDetail_Activated()
        End Sub

        Private Sub EmployeesListDetail_Saved()
        End Sub

        Private Sub SelectNextEmployee()
            Dim query = From employee In Employees
                        Where Not employee.IsCompleted
                        Select employee
            Dim nextEmployee = query.FirstOrDefault()

            If (Not nextEmployee Is Nothing) Then
                Employees.SelectedItem = nextEmployee
            End If
        End Sub
   End Class

Open in new window

Now every time you open the screen or press save in the screen it will automatically select the next record for which not all data was entered.

Author Comment

ID: 38364337
Thank you so much for your help!  You understood my question exactly and your solution sounds like it's exactly what I need!  The code you included will help me immensely.  I've maxed out points and will ask related question if needed.  Thanks again!

Author Closing Comment

ID: 38364346
Great solution.  Thanks again for the help and the code!

Expert Comment

by:Jean Marie Geeraerts
ID: 38366805
You're welcome. Feel free to send me a personal message to notify me about your question. Maybe EE should provide a seperate LightSwitch topic :-)

Author Comment

ID: 38501482
Are you by any chance available to help with this question?  I've re-posted it at...
When I was finally able to try your code I realized it was trying to run based off data on the left which in my case doesn't change.  I was unsuccessful in trying to taylor you code to get it to work.  I could really use your help.

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Since .Net 2.0, Visual Basic has made it easy to create a splash screen and set it via the "Splash Screen" drop down in the Project Properties.  A splash screen set in this manner is automatically created, displayed and closed by the framework itsel…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
Is your data getting by on basic protection measures? In today’s climate of debilitating malware and ransomware—like WannaCry—that may not be enough. You need to establish more than basics, like a recovery plan that protects both data and endpoints.…
With just a little bit of  SQL and VBA, many doors open to cool things like synchronize a list box to display data relevant to other information on a form.  If you have never written code or looked at an SQL statement before, no problem! ...  give i…

830 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question