如何修改DataGridView中某一列列头的颜色 如题哈不是修改全部的列头是某一列列头的颜色 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 试试下面的代码,代码来自http://bingning.net/VB/SOURCE/datagridview/cellcolor.html//列Header的背景色为黄色 DataGridView1.ColumnHeadersDefaultCellStyle.BackColor = Color.Yellow; //以下是一个写Gridview表头的事件函数,如果你也是这么写的动态表头的话,那么在tcHeader[4]的style位置,可以添加它的颜色,即表头的颜色。protected void GViewBudgetCmsRpt_RowCreated(object sender, GridViewRowEventArgs e) { switch (e.Row.RowType) { case DataControlRowType.Header: TableCellCollection tcHeader = e.Row.Cells; tcHeader.Clear(); tcHeader.Add(new TableHeaderCell()); tcHeader[0].Attributes.Add("rowspan", "2"); //跨Row tcHeader[0].Text = "预算编号"; tcHeader.Add(new TableHeaderCell()); tcHeader[1].Attributes.Add("rowspan", "2"); //跨Row tcHeader[1].Text = "预算科目"; tcHeader.Add(new TableHeaderCell()); tcHeader[2].Attributes.Add("rowspan", "2"); //跨Row tcHeader[2].Text = "币别"; tcHeader.Add(new TableHeaderCell()); tcHeader[3].Attributes.Add("rowspan", "2"); //跨Row tcHeader[3].Text = "预算总额"; tcHeader.Add(new TableHeaderCell()); tcHeader[4].Attributes.Add("colspan", "4"); //跨col tcHeader[4].Text = "XXXX年各月预算安排"; tcHeader[4].Text += "</tr><tr><th style='text-align: center' class='yy_sgv_fixRow yy_sgv_fixLow'>1-" + "1月预算(B)</th>"; tcHeader[4].Text += "<th style='text-align: center' class='yy_sgv_fixRow yy_sgv_fixLow'>实际(C)</th>"; tcHeader[4].Text += "<th style='text-align: center' class='yy_sgv_fixRow yy_sgv_fixLow'>差额(D=C-B)</th>"; tcHeader[4].Text += "<th style='text-align: center' class='yy_sgv_fixRow yy_sgv_fixLow'>备注</th></tr>"; break; } } 终于让我找到了 DataGridView1.EnableHeadersVisualStyles = false; DataGridView1.Columns[0].HeaderCell.Style.BackColor = Color.Blue; //DataGridView1.Columns[i] i写你想要的列号就可以了 DataGridView1.Columns[1].HeaderCell.Style.BackColor = Color.Black dataGridView1.EnableHeadersVisualStyles = false; dataGridView1.Columns[1].HeaderCell.Style.BackColor = Color.Red; tabControl控件怎么实现透明 JavaScript没没没没没反应 正则表达式的问题(字符替换) C# 操作Excel 的问题 C#开发中Oracle数据库连接池问题 问个正则表达式 截取字符串的问题,紧急!!! 如何从数据库中下载文件 代码如何写 本人菜鸟 望各位赐教 急~急~急~急~急~急~急~winform问题(100) EF根据父节点求所有子节点,根据子节点求出所有父节点 dataGridView1_CellClick C#线程到底是干什么的?怎么使用?有没有简单的例子
DataGridView1.ColumnHeadersDefaultCellStyle.BackColor = Color.Yellow;
{
switch (e.Row.RowType)
{
case DataControlRowType.Header: TableCellCollection tcHeader = e.Row.Cells;
tcHeader.Clear(); tcHeader.Add(new TableHeaderCell());
tcHeader[0].Attributes.Add("rowspan", "2"); //跨Row
tcHeader[0].Text = "预算编号"; tcHeader.Add(new TableHeaderCell());
tcHeader[1].Attributes.Add("rowspan", "2"); //跨Row
tcHeader[1].Text = "预算科目"; tcHeader.Add(new TableHeaderCell());
tcHeader[2].Attributes.Add("rowspan", "2"); //跨Row
tcHeader[2].Text = "币别"; tcHeader.Add(new TableHeaderCell());
tcHeader[3].Attributes.Add("rowspan", "2"); //跨Row
tcHeader[3].Text = "预算总额"; tcHeader.Add(new TableHeaderCell());
tcHeader[4].Attributes.Add("colspan", "4"); //跨col
tcHeader[4].Text = "XXXX年各月预算安排"; tcHeader[4].Text += "</tr><tr><th style='text-align: center' class='yy_sgv_fixRow yy_sgv_fixLow'>1-" + "1月预算(B)</th>";
tcHeader[4].Text += "<th style='text-align: center' class='yy_sgv_fixRow yy_sgv_fixLow'>实际(C)</th>";
tcHeader[4].Text += "<th style='text-align: center' class='yy_sgv_fixRow yy_sgv_fixLow'>差额(D=C-B)</th>";
tcHeader[4].Text += "<th style='text-align: center' class='yy_sgv_fixRow yy_sgv_fixLow'>备注</th></tr>"; break;
}
}
DataGridView1.Columns[0].HeaderCell.Style.BackColor = Color.Blue;
//DataGridView1.Columns[i] i写你想要的列号就可以了
DataGridView1.Columns[1].HeaderCell.Style.BackColor = Color.Black
dataGridView1.EnableHeadersVisualStyles = false;
dataGridView1.Columns[1].HeaderCell.Style.BackColor = Color.Red;