I have two datagridview cells, grid1 and grid2. am i loading the files to both grid, i have used the version of the file. every time when i Save/edit a file it increment a file version by 1 from 5, which means it will be 6,7,8,9 etc.
file version starts from 5. Increment it is working with no problem
I want to change the background color of the cell if i loaded the file and edit, from that cell edited, it must change the background color to yellow.
- Load existing file
- Edit the file
- Background color of the edited cell must change to yellow
- Save the file and clear the color (this is working)
I have tried this but,it is highlighting the color when i created the file. i only need it to change background cell color only on editing the file.
my code:
int version_Number = 5;
string _OriginalValue;
private void Grid1_CellBeginEdit_1(object sender, DataGridViewCellCancelEventArgs e)
{
try
{
_OriginalValue = Grid1[e.ColumnIndex, e.RowIndex].Value.ToString();
}
catch (Exception ex)
{
MessageBox.Show("Error occured.\nError message: " + ex.Message, "Error Occured", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
#region Grid2_CellEndEdit_1
private void Grid2_CellEndEdit_1(object sender, DataGridViewCellEventArgs e)
{
try
{
DataGridViewCell cell = Grid2[e.ColumnIndex, e.RowIndex];
if (cell.Value.ToString() != _OriginalValue)
{
if (version_Number >= 1000)
{
cell.Style.BackColor = Color.Yellow;
}
}
You have to handle the part that colors the cell in the cellformating event, a sample i tried is as below