Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>If I understand your situation properly, you can achieve what you are looking for by handling the <code>DataGridView.CellValueChanged</code> event. This prevents you from having to loop through all your rows. In theory, this should work as you populate the DGV control. </p> <p>Here is a very crude example of what I am talking about. You will likely need to play with it to make it work for your specific situation. In my case, it adjusts the <code>Style.Backcolor</code> of a cell when a changed value is committed. Since there is the possibility that there will only be a single row when data is entered, I set up a conditional to handle this case as well. </p> <p>If this is the Winforms DGV control, you need to use the <code>Cell.Style.BackColor</code> Property, not the <code>Cell.BackColor</code> property (which doesn't exist on the Winforms DGV) in your code. </p> <p>You will have to refine the code to suit your circumstances . . . </p> <pre><code> private void Form1_Load(object sender, EventArgs e) { // Add a handler for the cell value changed event: this.myDataGridView.CellValueChanged += new DataGridViewCellEventHandler(myDataGridView_CellValueChanged); } void myDataGridView_CellValueChanged(object sender, DataGridViewCellEventArgs e) { // grab a reference to the changed cell: DataGridViewCell cell = myDataGridView.Rows[e.RowIndex].Cells["contract_id"]; // Guard against the case where this is the first row in the DGV table: if (cell.RowIndex - 1 &gt;= 0) { if (cell.Value != myDataGridView.Rows[cell.RowIndex - 1].Cells["contract_id"].Value) { // CHange the Style.BackColor property for the cell: myDataGridView.CurrentRow.Cells["contract_id"].Style.BackColor = Color.Blue; } } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload