How to change one DataGridView column header color to red at runtime [Resolved]

Posted by Amulya under C# on 8/18/2013 | Points: 10 | Views : 3819 | Status : [Member] | Replies : 1
How to change one DataGridView column header color to red at runtime




Responses

Posted by: Satyapriyanayak on: 8/18/2013 [Member] [MVP] Silver | Points: 50

Up
0
Down

Resolved
First you have to load one column data at runtime to datagridview and then write two lines of code

dataGridView1.Columns[0].HeaderCell.Style.ForeColor = Color.Red;
dataGridView1.EnableHeadersVisualStyles = false;


private void Form1_Load(object sender, EventArgs e)
{
con.Open();
str = "select ProductName from product";
com = new SqlCommand(str, con);
ds = new DataSet();
sqlda = new SqlDataAdapter(com);
sqlda.Fill(ds, "product");
con.Close();
dataGridView1.DataSource = ds;
dataGridView1.DataMember = "product";
dataGridView1.Columns[0].HeaderCell.Style.ForeColor = Color.Red;
dataGridView1.EnableHeadersVisualStyles = false;
}


If this post helps you mark it as answer
Thanks

Amulya, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response