none
For each loop to update related field in datagrid RRS feed

  • Question

  • I have 2 related tables:

    Contracts and ContractStatus

    I have a screen with a datagrid allowing me to search the contracts entity for expired contracts based on a date range.

    Using Yann's solution for enabling multiple row selection (https://code.msdn.microsoft.com/How-To-Enable-Multiple-Row-0ca9662c#content) I am then trying to create a button that will update the ContractStatus field of the selected contract rows to "Chargeable" but am having trouble finding the right expression.  I can update other fields using this method fine, just not the ContractStatus field.  

    This is what I have so far:

    Private Sub UpdateToChargeable_Execute()
                'if the variable hasn't been set, just leave, there's nothing more we can do here 
                If (_itemsControl Is Nothing) Then Return

                Dim count As Integer
                count = 0

                'loop through the selected rows
                For Each row As Contract In _itemsControl.SelectedItems

                    row.ContractStatus = 

                    count = count + 1

                Next

     End Sub

    After row.ContractStatus = it won't accept an integer (the id) or a string (the description).  The error i get is "Value of type 'String' cannot be converted to 'LightswitchApplication.ContractStatus'.

    Any ideas on what I am doing wrong?

    Many thanks




    • Edited by jcsf1 Friday, February 1, 2019 11:09 AM
    Friday, February 1, 2019 10:59 AM

All replies

  • Problem resolved.

    I had to set a variable to the ContractStatus entity ID and then use the variable in the row.contractstatus = expression.  My code now looks like this:

    Private Sub UpdateToChargeable_Execute()
                'if the variable hasn't been set, just leave, there's nothing more we can do here 
                If (_itemsControl Is Nothing) Then Return

                Dim count As Integer
                count = 0

        Dim status As ContractStatus = DataWorkspace.ApplicationData.ContractStatusSet_Single(3)

                'loop through the selected rows
                For Each row As Contract In _itemsControl.SelectedItems

                    row.ContractStatus = status

                    count = count + 1

                Next

            End Sub


    Friday, February 1, 2019 11:23 AM