Problem with DataView and PropertyChanged event RRS feed

  • General discussion

  • Hello.


    I just run into a problem using the PropertyChanged event of the DataRowView. It took me a few hours to track it down because it occured in a fairly complex piece of code so at first I believed it was my fault. I think I've found the explanation and want to tell you what I've found out in case you have a similar problem.


    The PropertyChanged event should fire if a value of a column of the underlying DataRow changes, but it's working only for the first DataRowView referencing the DataRow. Below is an example for that behaviour - the second event handler Row2_PropertyChanged is never called!


    Using the .NET Reflector I discovered that the OnListChanged method of the DataView class calls the internal ResetLastChangedColumn method - that's why only one PropertyChanged event is raised. I think that's a bug in the DataView class ...


    Greetings from Munich,



    ---------- snip ----------


    Module Module1

    Dim Table As DataTable

    Dim View As DataView

    Dim WithEvents Row As DataRowView

    Dim View2 As DataView

    Dim WithEvents Row2 As DataRowView

    Sub Main()

    Table = New DataTable

    Table.Columns.Add("ID", GetType(Integer))

    Table.Columns.Add("Name", GetType(String))

    Table.Rows.Add(1, "VS 2005")

    View = New DataView(Table, "ID=1", "", DataViewRowState.CurrentRows)

    Row = View(0)

    Table.Rows(0)("Name") = "Visual Studio"

    View2 = New DataView(Table, "ID=1", "", DataViewRowState.CurrentRows)

    Row2 = View2(0)

    Table.Rows(0)("Name") = "Visual Studio 2005"



    End Sub

    Private Sub Row_PropertyChanged(ByVal sender As Object, ByVal e As System.ComponentModel.PropertyChangedEventArgs) Handles Row.PropertyChanged

    Debug.WriteLine("Row: " & e.PropertyName)

    End Sub

    Private Sub Row2_PropertyChanged(ByVal sender As Object, ByVal e As System.ComponentModel.PropertyChangedEventArgs) Handles Row2.PropertyChanged

    Debug.WriteLine("Row2: " & e.PropertyName)

    End Sub

    End Module

    Wednesday, August 22, 2007 7:32 AM