We help IT Professionals succeed at work.

Add detail records in same order as list

BobRosas asked
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?
Watch Question

Application Engineer
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.


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!


Great solution.  Thanks again for the help and the code!
Jean Marie GeeraertsApplication Engineer

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 :-)


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.

Explore More ContentExplore courses, solutions, and other research materials related to this topic.