[SOLVED] DataGridView ForeColor

Answered Closed
0
0

Hi Wisej,

DataGridView ForeColor not change at runtime.

How to change ForeColor at runtime?

Thank you.

Attachment
  • You must to post comments
Best Answer
0
0

The DataGridView doesn’t have the ForeColor property, like in WinForms.

You can set the ForeColor like this:

  • this.Column1.HeaderStyle.ForeColor.
  • this.dataGrid1.Rows[0].DefaultCellStyle.ForeColor;
  • this.dataGridView1.DefaultCellStyle.ForeColor;
  • this.Column1.DefaultCellStyle.ForeColor;
  • this.dataGridView1.Rows[0].Cells[0].Style.ForeColor;
  • this.dataGridView1.Rows[0].HeaderCell.Style.ForeColor;
  • this.dataGridView1.TopLeftHeaderCell.Style.ForeColor;
  • this.dataGridView1.RowTemplate.DefaultCellStyle.ForeColor;

 

 

 

 

 

 

  • Huỳnh Tấn Phát
    I am using this.dataGridView1.RowTemplate.DefaultCellStyle.ForeColor. But it is not changing at runtime. You can see my demo
  • Luca (ITG)
    The RowTemplate is the template object used to create new rows. I won’t change the existing rows. You can assign it to your own row template object as well. The grid will clone it.
  • You must to post comments
0
0

I was able to get the cells’ ForeColor to change in your demo by changing the ForeColor property of DataGridView1.DefaultCellStyle (rather than DataGridView1.RowTemplate.DefaultCellStyle), and then by calling Refresh() on the data grid view to update its appearance.

So in your demo the line
Me.DataGridView1.RowTemplate.DefaultCellStyle.ForeColor = dlg.Color
Gets replaced with
Me.DataGridView1.DefaultCellStyle.ForeColor = dlg.Color 'changes the color
Me.DataGridView1.Refresh() 'update appearance

 

  • You must to post comments
Showing 2 results