Click here to Skip to main content
15,896,522 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi everyone!

I have been looking at my code for so long that I cannot longer see what is wrong with it.

I have a class Survey that implements INotifyPropertyChanged. There are two properties relevant to my question, TotalPoints and TotalAdjustedPoints:

VB
Public Property TotalPoints() As Long
      Get
          TotalPoints = lTotalPoints
      End Get
      Set(ByVal value As Long)
          If value <> lTotalPoints Then
              Me.lTotalPoints = value
              NotifyPropertyChanged("TotalPoints")
          End If
      End Set
  End Property

  Public Property TotalAdjustedPoints() As Long
      Get
          TotalAdjustedPoints = lTotalAdjustedPoints
      End Get
      Set(ByVal value As Long)
          If value <> lTotalAdjustedPoints Then
              Me.lTotalAdjustedPoints = value
              NotifyPropertyChanged("TotalAdjustedPoints")
          End If
      End Set
  End Property


I have an ObservableCollection of Survey instances that is used as ItemsSource for a list view. The listview is defined in XAML, like this:

XML
<ListView Name="lvSurveyManagement" Grid.Row="0" Grid.Column="0" Grid.ColumnSpan="4" Margin="5,5,5,5">
    <ListView.View>
        <GridView>
            <GridViewColumn  x:Name="colSurveyGUID"  Width="300" DisplayMemberBinding="{Binding Path=SurveyGUID}"/>
            <GridViewColumn  x:Name="colSurveyLineGUID"  Width="100" DisplayMemberBinding="{Binding Path=LineGUID}"/>
            <GridViewColumn  x:Name="colSurveyType"  Width="100" DisplayMemberBinding="{Binding Path=SurveyType}"/>
            <GridViewColumn  x:Name="colLoadedPoints"  Width="122" DisplayMemberBinding="{Binding Path=TotalPoints}"/>
            <GridViewColumn  x:Name="colAdjustedPoints"  Width="122" DisplayMemberBinding="{Binding Path=TotalAdjustedPoints}"/>
        </GridView>
    </ListView.View>
</ListView>


When I update the above mentioned properties for a Survey object belonging to the ObservableCOllection, the change in TotalAdjustedPoints is reflected in the listview, but the change in TotalPoints is not.

I honestly don't see what I am doing wrong, hope someone here can help me. Thank you in advance.
Posted

1 solution

Ok... nothing like asking the question to see what was wrong with my code!

It turns out I was updating the properties like this:


VB
bDelete = Me.pSurvey.deleteSurveyPoints()
            If bDelete Then
                '...
                Me.pSurvey.TotalPoints = 0 'DOES NOT WORK
                Me.pSurvey.TotalAdjustedPoints = 0 'WORKS OK   


But the problem was that inside Survey.deleteSurveyPoints I had a line:

Me.lTotalPoints = 0

Hence value <> lTotalPoints (property set) would never be verified and the PropertyChanged event would never be raised!
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900