tonn

Hi,

In a DataGridView I need to indicate cells having a value changed by the user. At the moment I use the CellValueChanged event to set the cell font to bold upon a change of value:

private void dataGridView_CellValueChanged(object sender, DataGridViewCellEventArgs e)
{
DataGridViewCell cell = dataGridView.Rows[e.RowIndex].Cells[e.ColumnIndex];
cell.Style.Font =
new Font(dataGridView.Font, FontStyle.Bold);
}

However the cell should also revert to normal (not bold) if the user happens to restore the original value.

Where do I find the original value to compare with
Is there a better way
Note: the DataGridView's DataSource property is set to a DataTable loaded from a database.

Your help will be much appreciated.
Regards, Tonn



Re: Windows Forms Data Controls and Databinding How to: indicate changed value in DataGridView?

Damiaan

You can compare the new value with the original value from the DataTable you are using as the datasource.





Re: Windows Forms Data Controls and Databinding How to: indicate changed value in DataGridView?

tonn

Hi Damiaan, thanks for your response.

However due to the databinding the DataTable is already updated and doesn't present the original values anymore. I can call GetChanges() on the DataTable but these also contain the new values.

Obviously the original values must be present somewhere inside the DataTable since a call to RejectChanges() reverts to them. But the DataTable doesn't seem to expose these.
Am I missing something





Re: Windows Forms Data Controls and Databinding How to: indicate changed value in DataGridView?

Damiaan

Have you tried with the DataRowVersion

DataRow[Datacolumn, DataRowVersion.Original]

See also on MSDN "Row States and Row versions".





Re: Windows Forms Data Controls and Databinding How to: indicate changed value in DataGridView?

tonn

Thanks Damiaan, that's what I was looking for.