I have an ObservableCollection TableRows
of this struct binded to a DataGrid:
public class TableStruct
{
public string Item1 {get; set;}
public string Item2 {get; set;}
public string Item3 {get; set;}
public string Item4 {get; set;}
public string Item5 {get; set;}
public string Item6 {get; set;}
}
When trying to update individual items in a row, I tried doing it like this:
for(int i = 0; i < TableRows.Count; i++)
{
if(SomeConditional)
{
TableStruct new_row = TableRows[i];
new_row.Item3 = "changed";
TableRows[i] = new_row;
}
}
But when running the program the DataGrid is not updated. however running this code does update to the DataGrid and works as intended:
for(int i = 0; i < TableRows.Count; i++)
{
if(SomeConditional)
{
TableStruct new_row = new TableStruct();
new_row.Item1 = "same";
new_row.Item2 = "same";
new_row.Item3 = "changed";
new_row.Item4 = "same";
new_row.Item5 = "same";
new_row.Item6 = "same";
TableRows[i] = new_row;
}
}
What is different here? In my mind they both accomplish the same task but one takes more lines than the other.