如题哈
不是修改全部的列头
是某一列列头的颜色

解决方案 »

  1.   

    试试下面的代码,代码来自http://bingning.net/VB/SOURCE/datagridview/cellcolor.html//列Header的背景色为黄色
     DataGridView1.ColumnHeadersDefaultCellStyle.BackColor = Color.Yellow;
      

  2.   

    //以下是一个写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;
            }
        }
      

  3.   

    终于让我找到了 DataGridView1.EnableHeadersVisualStyles = false;
     DataGridView1.Columns[0].HeaderCell.Style.BackColor = Color.Blue;
     //DataGridView1.Columns[i] i写你想要的列号就可以了
      

  4.   


    DataGridView1.Columns[1].HeaderCell.Style.BackColor = Color.Black
      

  5.   


      dataGridView1.EnableHeadersVisualStyles = false;
      dataGridView1.Columns[1].HeaderCell.Style.BackColor = Color.Red;