Click here to Skip to main content
15,885,278 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
How to edit, update datagridview and give color to the cell depends on value of cell in windows forms.
any one know please reply

Thanks & Regards
lakshman
Posted

here in example if checkbox cell of particular row is cecked then I am changing color of row ...

Use CurrentCellDirtyStateChanged event put color changing code stuff inside
C#
Private void dgv1_CurrentCellDirtyStateChanged(Object sender, System.EventArgs e) 
{
            If (dgv1.IsCurrentCellDirty)
            {
                dgv1.CommitEdit(DataGridViewDataErrorContexts.Commit)
                If (dgv1.CurrentCell.ColumnIndex == 1)
                {  
                    oCell = dgv1.Rows[dgv1.CurrentCell.RowIndex].Cells[0] as DataGridViewCheckBoxCell;
                       bool bChecked = (null != oCell && null != oCell.Value && true == (bool)oCell.Value);
                       if (true == bChecked)
                       {
                          dgv1.Rows[dgv1.CurrentCell.RowIndex].DefaultCellStyle.BackColor = Color.Yellow;
                       }                  
                    else
                    {
                         dgv1.Rows[dgv1.CurrentCell.RowIndex].DefaultCellStyle.BackColor = Color.Green;
                    }
                }
            }
} 

Happy Coding!
:)
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900