如何修改DataGridView中某一列列头的颜色

zhaigates 2009-05-15 09:53:15
如题哈
不是修改全部的列头
是某一列列头的颜色
...全文
2314 16 打赏 收藏 转发到动态 举报
写回复
用AI写文章
16 条回复
切换为时间正序
请发表友善的回复…
发表回复
dreamgis 2011-11-04
  • 打赏
  • 举报
回复
有帮助,,解决了 分享一下,,做得对
xyq_bucai 2011-08-28
  • 打赏
  • 举报
回复
顶,不错!
坐看昀起 2010-02-22
  • 打赏
  • 举报
回复 2

dataGridView1.EnableHeadersVisualStyles = false;
dataGridView1.Columns[1].HeaderCell.Style.BackColor = Color.Red;
InterRonaldo 2009-09-02
  • 打赏
  • 举报
回复
好帖 顶一下!
CqCoder 2009-05-17
  • 打赏
  • 举报
回复
[Quote=引用 8 楼 surlew 的回复:]
终于让我找到了

C# code
DataGridView1.EnableHeadersVisualStyles = false;
DataGridView1.Columns[0].HeaderCell.Style.BackColor = Color.Blue;
//DataGridView1.Columns[i] i写你想要的列号就可以了
[/Quote]GOOD`
zhaigates 2009-05-17
  • 打赏
  • 举报
回复
[Quote=引用 8 楼 surlew 的回复:]
终于让我找到了
C# codeDataGridView1.EnableHeadersVisualStyles=false;
DataGridView1.Columns[0].HeaderCell.Style.BackColor=Color.Blue;//DataGridView1.Columns[i] i写你想要的列号就可以了
[/Quote]
3Q very much...........
东京老树根 2009-05-15
  • 打赏
  • 举报
回复
//以下是一个写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;
}
}
zhaigates 2009-05-15
  • 打赏
  • 举报
回复
恩,不知道有没有,我觉得应该可以有
surlew 2009-05-15
  • 打赏
  • 举报
回复
楼上的是设置全部列头颜色,设置某个好像真的没什么办法...
outou 2009-05-15
  • 打赏
  • 举报
回复
试试下面的代码,代码来自http://bingning.net/VB/SOURCE/datagridview/cellcolor.html

//列Header的背景色为黄色
DataGridView1.ColumnHeadersDefaultCellStyle.BackColor = Color.Yellow;

surlew 2009-05-15
  • 打赏
  • 举报
回复
貌似没办法,如果要突出显示的话,我觉得在下面的单元格变颜色效果也不错
zhaigates 2009-05-15
  • 打赏
  • 举报
回复
这一列是动态加上去的
outou 2009-05-15
  • 打赏
  • 举报
回复

DataGridView1.Columns[1].HeaderCell.Style.BackColor = Color.Black
surlew 2009-05-15
  • 打赏
  • 举报
回复
终于让我找到了

DataGridView1.EnableHeadersVisualStyles = false;
DataGridView1.Columns[0].HeaderCell.Style.BackColor = Color.Blue;
//DataGridView1.Columns[i] i写你想要的列号就可以了
zhaigates 2009-05-15
  • 打赏
  • 举报
回复
呃,楼上方案对我的不太适合...
DataGridView控件用法合集 1. DataGridView当前的单元格属性取得、变更 2. DataGridView编辑属性 3. DataGridView最下面一列新追加行非表示 4. DataGridView判断当前选行是否为新追加的行 5. DataGridView删除行可否设定 6. DataGridView行列不表示和删除 7. DataGridView行列宽度高度设置为不能编辑 8. DataGridView行高列幅自动调整 9. DataGridView指定行列冻结 10. DataGridView列顺序变更可否设定 11. DataGridView行复数选择 12. DataGridView选择的行、列、单元格取得 13. DataGridView指定单元格是否表示 14. DataGridView表头部单元格取得 15. DataGridView表头部单元格文字列设定 16. DataGridView选择的部分拷贝至剪贴板 17. DataGridView粘贴 18. DataGridView单元格上ToolTip表示设定(鼠标移动到相应单元格上时,弹出说明信息) 19. DataGridView的ContextMenuStrip属性 20. DataGridView指定滚动框位置 21. DataGridView手动追加列 22. DataGridView全体分界线样式设置 23. DataGridView根据单元格属性更改显示内容 24. DataGridView新追加行的行高样式设置る 25. DataGridView新追加行单元格默认值设置 26. DataGridView单元格数据错误标签表示 27. DataGridView单元格内输入值正确性判断 28. DataGridView单元格输入错误值事件的捕获 29. DataGridView行排序(点击列表头自动排序的设置) 30. DataGridView自动行排序(新追加值也会自动排序) 31. DataGridView自动行排序禁止情况下的排序 32. DataGridView指定列指定排序 33. DataGridView单元格样式设置 34. DataGridView文字表示位置的设定 35. DataGridView单元格内文字列换行 36. DataGridView单元格DBNull值表示的设定 37. DataGridView单元格样式格式化 38. DataGridView指定单元格颜色设定 39. DataGridView单元格文字字体设置 40. DataGridView根据单元格值设定单元格样式 41. DataGridView设置单元格背景颜色 42. DataGridView行样式描画 43. DataGridView显示行号 44. DataGridView焦点所在单元格焦点框不显示的设定 45. DataGridView显示选择框CheckBox 46. DataGridView显示下拉框ComboBox 47. DataGridView单击打开下拉框 48. DataGridView显示按钮 49. DataGridView显示链接 50. DataGridView显示图像 51. DataGridView编辑单元格控件取得 52. DataGridView输入自动完成 53. DataGridView单元格编辑时键盘KEY事件取得 54. DataGridView下拉框(ComboBox)单元格编辑时事件取得 55. DataGridView下拉框(ComboBox)单元格允许文字输入设定 56. DataGridView根据值不同在另一列显示相应图片 57. DataGridView显示进度条(ProgressBar) 58. DataGridView添加MaskedTextBox 59. DataGridViewEnter键按下焦点移至旁边的单元格 60. DataGridView行集合化(Group)

111,120

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • AIGC Browser
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧