Click here to Skip to main content
15,899,313 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
I don't know where the Problem is? Can somebody help me please?

C#
this.dataGridView2.Columns["Status"].VALUE == "2".DefaultCellStyle.BackColor = Color.Yellow;


What I have tried:

Without Value it fits - but i Need to change the Color with VALUE
Posted
Updated 6-Aug-18 3:47am
v2

A column does not have a value. You need to read the value of the cell on the row you're interested in, and change that cell's colour.
C#
DataGridViewCell cell = this.dataGridView2.Rows[THE_ROW_INDEX].Cells["Status"];
if (cell.Value == "2")
{
    cell.Style.BackColor = Color.Yellow;
}
 
Share this answer
 
v3
Try this for column:

C#
dataGridView2.Columns["Status"].DefaultCellStyle.BackColor = Color.Yellow;


or this for cell:
C#
if (dataGridView1.Rows[0].Cells[0].Value == "2")
        dataGridView2.Rows[0].Cells[0].Style.BackColor = Color.Yellow;
 
Share this answer
 
v2
Comments
Richard Deeming 6-Aug-18 9:48am    
You've posted the same answer twice. :)
Leo Chapiro 6-Aug-18 9:53am    
Oh, sorry, I've removed the accidentally added answer. Thank you!

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