能否在dataGridView中对某个指定的单元格单独设置样式,比如背景颜色之类。
注:不是指一列或一行是指其中的一个单元格设置颜色。

解决方案 »

  1.   

    貌似可以
     e.Item.Cells(0).BackColor = System.Drawing.Color.Red
      

  2.   

     this.dataGridView1.Rows[2].Cells[1].Style.BackColor = Color.Red;
      

  3.   

    DataGridViewCellStyle style = new DataGridViewCellStyle();
    style.BackColor = Color.Red;
    dataGridView1.Rows[0].Cells[0].Style = style;
      

  4.   

    也可以,参考我在vb.net中的方法Public Class Form1    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
            For i As Integer = 0 To 9
                Me.DataGridView1.Rows.Add("Row" + i.ToString)
            Next
        End Sub    Private Sub DataGridView1_CellPainting(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellPaintingEventArgs) Handles DataGridView1.CellPainting
            Dim Rect As Rectangle = New Rectangle(e.CellBounds.X - 1, e.CellBounds.Y + 1, e.CellBounds.Width - 2, e.CellBounds.Height - 2)
            If e.RowIndex = 1 And e.ColumnIndex = 0 Then
                e.Graphics.DrawRectangle(Pens.Red, Rect)
                e.PaintContent(e.CellBounds)
                e.Handled = True
            End If
        End SubEnd Class
      

  5.   


     protected void gvFile_RowDataBound(object sender, GridViewRowEventArgs e)
    {
       this.dataGridView1.Rows[i].Cells[j].Style.BackColor = 颜色
    }
      

  6.   

    this.dataGridView1.CellBorderStyle =
        DataGridViewCellBorderStyle.None;
    this.dataGridView1.RowHeadersBorderStyle =
        DataGridViewHeaderBorderStyle.Single;
    this.dataGridView1.ColumnHeadersBorderStyle =
        DataGridViewHeaderBorderStyle.Single;这样可以吗?
      

  7.   

    private void printDocument1_PrintPage(object sender, PrintPageEventArgs e)
    e.Graphics.DrawRectangle(Pens.Red, Rect);//绘制矩形。
      

  8.   

    能this.dataGridView1.Rows[i].Cells[j].Style.BackColor = 颜色