DataGridView Changing Cell Color

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I want to change the cell color of a specific cell without going through an
event.

I tried using:

this.datagrid.Rows[0].Cells[0].InheritedStyle.BackColor = Color.LightGray;

but InheritedStyle doesn't seem to do it.
 
Hi,
Try this code:
DataTable dt = new DataTable();
DataColumn col1 = new DataColumn();
col1.DataType = typeof(System.String);
col1.ColumnName = "Name";

dt.Columns.Add(col1);

DataRow row1 = dt.NewRow();

row1["Name"] = "manish bafna";

DataRow row2 = dt.NewRow();
row2["Name"] = "sanjay bafna";

dt.Rows.Add(row1);
dt.Rows.Add(row2);

dataGridView1.DataSource = dt;

dataGridView1.EnableHeadersVisualStyles = false;
dataGridView1.Rows[0].Cells[0].Style.BackColor = Color.Yellow;
 
Back
Top