none
INotifyPropertyChanged issue

    Question

  • I'm using the below code in the SelectionChanged

    Dim selectedItem = Me.POInventoryItems.SelectedItem
    
                If (selectedItem Is Nothing) Then Return
                Dispatchers.Main.BeginInvoke(
                    Sub()
                        RemoveHandler DirectCast(selectedItem, INotifyPropertyChanged).PropertyChanged, AddressOf PropertyChanged
                        AddHandler DirectCast(selectedItem, INotifyPropertyChanged).PropertyChanged, AddressOf PropertyChanged
                    End Sub)

    And then the other code block is

    Private Sub PropertyChanged(ByVal sender As Object, ByVal e As PropertyChangedEventArgs)
                
                Select Case e.PropertyName
                    Case "BackOrderQuantity"
                        Me.POInventoryItems.SelectedItem.ReceivedQuantity = QtyOrdered - Me.POInventoryItems.SelectedItem.BackOrderQuantity
                        If Me.POInventoryItems.SelectedItem.BackOrderQuantity < 0 Then
                            If Me.ShowMessageBox("Back order value cannot be less than zero", "Validation Warning", MessageBoxOption.Ok) Then
                                Me.POInventoryItems.SelectedItem.BackOrderQuantity = 0
                            End If
                        End If
    
                        If Me.POInventoryItems.SelectedItem.BackOrderQuantity > QtyOrdered Then
                            If Me.ShowMessageBox("You can not increase the back ordered quantity higher than the Quantity ordered.", "Validation Warning", MessageBoxOption.Ok) Then
                                Me.POInventoryItems.SelectedItem.BackOrderQuantity = CurrentBOQty
                            End If
                        End If
                        If Me.POInventoryItems.SelectedItem.BackOrderQuantity = 0 Then
                            Me.POInventoryItems.SelectedItem.StockStatus = "In Stock"
                        End If
    
                End Select
            End Sub

    My problem is that if I press enter or click/select a deferent row then the property of the "ReceivedQuantity" is not changed.

    Can you help me resolve this please.


    Neil Thibeault

    Monday, August 19, 2013 3:42 AM

Answers

  • Why would you expect ReceivedQuantity to be changed? Selecting a different row only changes the SelectedItem property of the POInventoryItems collection, and nowhere in this code do you change ReceivedQuntity.

    I think you really should write this code in the BackOrderQuantity_Changed and BackOrderQuantity_Validate methods on the entity instead of implementing this code in the screen.


    Justin Anderson, LightSwitch Development Team

    • Marked as answer by NeilThibeault Tuesday, August 20, 2013 4:10 AM
    Monday, August 19, 2013 4:30 AM
    Moderator

All replies

  • Why would you expect ReceivedQuantity to be changed? Selecting a different row only changes the SelectedItem property of the POInventoryItems collection, and nowhere in this code do you change ReceivedQuntity.

    I think you really should write this code in the BackOrderQuantity_Changed and BackOrderQuantity_Validate methods on the entity instead of implementing this code in the screen.


    Justin Anderson, LightSwitch Development Team

    • Marked as answer by NeilThibeault Tuesday, August 20, 2013 4:10 AM
    Monday, August 19, 2013 4:30 AM
    Moderator
  • ReceivedQuantity changes on this line in the second code block.

    Me.POInventoryItems.SelectedItem.ReceivedQuantity = QtyOrdered - Me.POInventoryItems.SelectedItem.BackOrderQuantity

    I'll look into making the adjustments as you mentioned but I was thinking that having this in screen so that the end user can seen the changes they make right away.

    Is there away to have the _selectedChanged fire immediately rather than wait until the user moves to another row cell/property?


    Neil Thibeault

    Monday, August 19, 2013 11:43 AM
  • Thanks for the help.

    I rewrote the code as you suggested and now I can't believe I tried all that using the iNotifyPropertyChanged.

    I got a nice speed increase as well.


    Neil Thibeault

    Tuesday, August 20, 2013 4:10 AM