DataGridView Changing Cell Color

DataGridView Changing Cell Color

Post by UGV0ZX » Fri, 14 Sep 2007 06:36:03


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.
 
 
 

DataGridView Changing Cell Color

Post by TWFuaXNoIE » Fri, 14 Sep 2007 14:34:01

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;
--
Hope this helps.
Thanks and Regards.
Manish Bafna.
MCP and MCTS.