How to programmatically set cell value in DataGridView?

If the DataGridView is databound, you shouldn’t directly modify the content of the cell. Instead, you should modify the databound object. You can access that object through the DataBoundItem of the DataGridViewRow :

MyObject obj = (MyObject)dataGridView.CurrentRow.DataBoundItem;
obj.MyProperty = newValue;

Note that the bound object should implement INotifyPropertyChanged so that the change is reflected in the DataGridView

Leave a Comment