Add detail records in same order as list

Posted on 2012-08-13
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
    LVL 8

    Accepted Solution

    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

    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

    Great solution.  Thanks again for the help and the code!
    LVL 8

    Expert Comment

    by:Jean Marie Geeraerts
    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

    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.

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Why You Should Analyze Threat Actor TTPs

    After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

    This article explains how to create and use a custom WaterMark textbox class.  The custom WaterMark textbox class allows you to set the WaterMark Background Color and WaterMark text at design time.   IMAGE OF WATERMARKS STEPS Create VB …
    A while ago, I was working on a Windows Forms application and I needed a special label control with reflection (glass) effect to show some titles in a stylish way. I've always enjoyed working with graphics, but it's never too clever to re-invent …
    This video discusses moving either the default database or any database to a new volume.
    In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor ( If you're interested in additional methods for monitoring bandwidt…

    779 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

    Need Help in Real-Time?

    Connect with top rated Experts

    11 Experts available now in Live!

    Get 1:1 Help Now