Setting IsDirty property of a class gets Reset

RogerSchlueter-7899 1,466 Reputation points
2025-08-02T00:52:03.9+00:00

I am reading properties into a Person class:

Public Class Person
	Implements INotifyPropertyChanged
	
	Public Property PersonID
	Public Property IsDirty
	....
End Class


(I've omitted details and other properties that are irrelevant.)

The data are read into an ObservableCollection (Of Person) using this subroutine:

Public Sub PopulatePeople()
	....
	Dim com As New SqlCommand("Get_People", con) With {.CommandType = CommandType.StoredProcedure}
	Dim rdr As SqlDataReader = com.ExecuteReader
	While rdr.Read
		p = New Person With
		{
		.PersonID = rdr.GetInt32("PersonID"),
		<< all the other properties >>
		.IsDirty = False
		}
		ocPeople.Add(p)
		Debug.WriteLine($"{p.PersonID}   {p.IsDirty}")
	End While
End Sub

That debug statement shows the correct PersonID but shows that p.IsDirty = True for every person. I can't figure out why.

Windows development | Windows App SDK
{count} votes

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.