Set value of DataRowView

682 Views Asked by At

I am looking to modify a DataRowView value from an event.

I have tried the following but it never changes the DataGridCheckBoxColumn

((DataRowView)repDataGrid.SelectedItem).Row.ItemArray[4] = true;
1

There are 1 best solutions below

0
Tim Schmelter On BEST ANSWER

ItemArray creates a new object[] which can be used to read the values. But you can't use it to set them. You can use the DataRow indexer:

((DataRowView)repDataGrid.SelectedItem).Row[4] = true;

If you wanted to use ItemArray to assign the values you have to re-assign it:

DataRow row = (DataRowView)repDataGrid.SelectedItem).Row;
object[] fields = row.ItemArray;
fields[4] = true;
row.ItemArray = fields;