请教:如题,有没有相关的,或可否实现?

解决方案 »

  1.   

    先解决颜色的问题protected override void Paint(Graphics g, Rectangle Bounds, CurrencyManager Source,
                                  int RowNum, Brush BackBrush, Brush ForeBrush, 
                                  bool AlignToRight) 
    {
        
        bool bdel = (bool) GetColumnValueAtRow(Source, RowNum);    if(bdel == true)
            BackBrush = Brushes.Coral;
        else
            BackBrush = Brushes.White;    g.FillRectangle(BackBrush, Bounds.X, Bounds.Y, Bounds.Width, Bounds.Height);    System.Drawing.Font font = new Font(System.Drawing.FontFamily.GenericSansSerif, 
                                            (float)8.25 );
        g.DrawString( bdel.ToString(), font, Brushes.Black, Bounds.X, Bounds.Y);
    }private void CreateDataGridStyle() 
    {
        DataGridColumnStyle GridDelColumn;
        DataGridColumnStyle GridSeqStyle;
        DGStyle = new DataGridTableStyle();  //DGStyle is DataGridTableStyle    DGStyle.MappingName = "Table1";    GridSeqStyle = new DataGridTextBoxColumn();
        GridSeqStyle.MappingName = "Column1";
        GridSeqStyle.HeaderText = "Column1";
        GridSeqStyle.Width = 100;
        DGStyle.GridColumnStyles.Add(GridSeqStyle);    PropertyDescriptorCollection pcol = this.BindingContext[myDataSet, 
                                                 "Table1"].GetItemProperties();    GridDelColumn = new ColumnStyle(pcol["Table1"]);
        GridDelColumn.MappingName = "Column2";
        GridDelColumn.HeaderText = "Column2";
        GridDelColumn.Width = 100;
        DGStyle.GridColumnStyles.Add(GridDelColumn);    DGStyle.AllowSorting         = true;
        DGStyle.RowHeadersVisible    = true;
    }完成之后添加到DataGrid中CreateDataGridStyle();
    myDataGrid.TableStyles.Add(DGStyle);myDataGrid.SetDataBinding(myDataSet,"Table1");文章原地址:http://www.codeproject.com/KB/cs/custom_datagridcolumnstyl.aspx可以看看
      

  2.   

    重写gridview控件
    列动态生成可使用ITemplate
    RowCreated  中设置
    e.Row.BackColor = System.Drawing.Color.Red; 
      

  3.   

    DataGridView 
      

  4.   

    创建完全可编辑的 DataGridhttp://www.cnblogs.com/qworld/archive/2005/02/28/110282.html
      

  5.   

    忘说明了,webform的
    变色不是ROW变色,而是单元格可以变色(背景色可以自己设置,也就是说一行可能有多个颜色)
      

  6.   

    动态生成要可以编辑各单元格这相当麻烦!
    但设置每个单元格不同颜色还是可以的,在RowCreated事件中进行,以下是设置三行三列不同的颜色:
       protected void GridView1_RowCreated(object sender, GridViewRowEventArgs e)
        {
            if (e.Row.RowType == DataControlRowType.DataRow)
            {
                TableCellCollection cells = e.Row.Cells;
                if (e.Row.RowIndex == 0)//第1行
                {
                    for (int i = 0; i < cells.Count; i++)
                    {
                        if (i == 0)//第1单元格
                            cells[i].BackColor = System.Drawing.Color.Red;
                        else if (i == 1)//第2单元格
                            cells[i].BackColor = System.Drawing.Color.Green;
                        else//其它单元格
                            cells[i].BackColor = System.Drawing.Color.Blue;
                    }
                }
                else if (e.Row.RowIndex == 1)//第2行
                {
                    for (int i = 0; i < cells.Count; i++)
                    {
                        if (i == 0)
                            cells[i].BackColor = System.Drawing.Color.Green;
                        else if (i == 1)
                            cells[i].BackColor = System.Drawing.Color.Blue;
                        else
                            cells[i].BackColor = System.Drawing.Color.Red;
                    }
                }
                else//其他行
                {
                    for (int i = 0; i < cells.Count; i++)
                    {
                        if (i == 0)
                            cells[i].BackColor = System.Drawing.Color.Blue;
                        else if (i == 1)
                            cells[i].BackColor = System.Drawing.Color.Red;
                        else
                            cells[i].BackColor = System.Drawing.Color.Green;
                    }
                }
             }