1

I want to change all the colours of text in rows in a column depending on the column name in C#. How would I accomplish this?

So far I've tried the following:

private void dataGridView1_CellFormatting(object sender, DataGridViewCellFormattingEventArgs e) { if (this.dataGridView1.Columns[e.ColumnIndex].Name == "DatePaid") { e.CellStyle.ForeColor = Color.Blue; } } 

The program builds - but it doesn't work at all

1
  • 1
    Unable to comment on my answer from.mobile. You have to put that code within form load Commented Dec 6, 2013 at 12:16

2 Answers 2

2

If you want to change particular colum forecolor then use this,

dataGridView1.Columns["DatePaid"].DefaultCellStyle.ForeColor = Color.Blue; 
Sign up to request clarification or add additional context in comments.

Comments

1

You could use a switch:

 switch (dataGridView1.Columns[e.ColumnIndex].Name) { case "DatePaid": dataGridView1.Columns[e.ColumnIndex].DefaultCellStyle.ForeColor = Color.Blue; break; case "Something": dataGridView1.Columns[e.ColumnIndex].DefaultCellStyle.ForeColor = Color.Red; break; } 

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.