不是修改全部的列头
是某一列列头的颜色
16 个解决方案
#1
这一列是动态加上去的
#2
貌似没办法,如果要突出显示的话,我觉得在下面的单元格变颜色效果也不错
#3
试试下面的代码,代码来自
http://bingning.net/VB/SOURCE/datagridview/cellcolor.html
//列Header的背景色为黄色
DataGridView1.ColumnHeadersDefaultCellStyle.BackColor = Color.Yellow;
#4
楼上的是设置全部列头颜色,设置某个好像真的没什么办法...
#5
恩,不知道有没有,我觉得应该可以有
#6
//以下是一个写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;
}
}
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;
}
}
#7
呃,楼上方案对我的不太适合...
#8
终于让我找到了
DataGridView1.EnableHeadersVisualStyles = false;
DataGridView1.Columns[0].HeaderCell.Style.BackColor = Color.Blue;
//DataGridView1.Columns[i] i写你想要的列号就可以了
#9
DataGridView1.Columns[1].HeaderCell.Style.BackColor = Color.Black
#10
GOOD`
#11
3Q very much...........
#12
好帖 顶一下!
#13
dataGridView1.EnableHeadersVisualStyles = false;
dataGridView1.Columns[1].HeaderCell.Style.BackColor = Color.Red;
#14
顶,不错!
#15
有帮助,,解决了 分享一下,,做得对
#16
#1
这一列是动态加上去的
#2
貌似没办法,如果要突出显示的话,我觉得在下面的单元格变颜色效果也不错
#3
试试下面的代码,代码来自
http://bingning.net/VB/SOURCE/datagridview/cellcolor.html
//列Header的背景色为黄色
DataGridView1.ColumnHeadersDefaultCellStyle.BackColor = Color.Yellow;
#4
楼上的是设置全部列头颜色,设置某个好像真的没什么办法...
#5
恩,不知道有没有,我觉得应该可以有
#6
//以下是一个写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;
}
}
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;
}
}
#7
呃,楼上方案对我的不太适合...
#8
终于让我找到了
DataGridView1.EnableHeadersVisualStyles = false;
DataGridView1.Columns[0].HeaderCell.Style.BackColor = Color.Blue;
//DataGridView1.Columns[i] i写你想要的列号就可以了
#9
DataGridView1.Columns[1].HeaderCell.Style.BackColor = Color.Black
#10
GOOD`
#11
3Q very much...........
#12
好帖 顶一下!
#13
dataGridView1.EnableHeadersVisualStyles = false;
dataGridView1.Columns[1].HeaderCell.Style.BackColor = Color.Red;
#14
顶,不错!
#15
有帮助,,解决了 分享一下,,做得对