在 Winform 开发中
能设置DataGridView 单元格的字体和颜色吗??
能设置DataGridView 单元格的字体和颜色吗??
能设置DataGridView 单元格的字体和颜色吗??

解决方案 »

  1.   

    在CellFormatting或CellPainting
    中处理
      

  2.   


    这两个都是dataGridView的事件 在事件里控制单元格的颜色或者样式
    在具体的话就贴代码了 
    private void datagridview1_cellformatting(object sender, datagridviewcellformattingeventargs e)
            {
                if (e.rowindex != -1 && e.columnindex == 1 && e.value != null && e.value.tostring() == "")
                {
                    e.cellstyle.backcolor = color.red;
                    e.cellstyle.forecolor = color.blue;
                    e.cellstyle.selectionbackcolor = color.blueviolet;
                }
            }
      

  3.   

     If dgv_Req.Rows(e.RowIndex).Cells("Ora_Number").Value.ToString = "C4RM02000-19" Then            e.CellStyle.BackColor = Color.Red
                e.CellStyle.ForeColor = Color.Blue
                e.CellStyle.SelectionBackColor = Color.BlueViolet
            End If我这样设置为什么整行的颜色都改变???我要判断改变颜色的单元格 是通过值来判断的
    我是通过某列的值来判断该单元格是否要 加 背景颜色。请问怎么来实现.
      

  4.   

    If dgv_Req.Rows(e.RowIndex).Cells("Ora_Number").Value.ToString = "C4RM02000-19" Then  e.CellStyle.BackColor = Color.Red
      e.CellStyle.ForeColor = Color.Blue
      e.CellStyle.SelectionBackColor = Color.BlueViolet
      End If我这样设置为什么整行的颜色都改变???我要判断改变颜色的单元格 是通过值来判断的
    我是通过某列的值来判断该单元格是否要 加 背景颜色。请问怎么来实现.
      

  5.   

    private void datagridview1_cellformatting(object sender, datagridviewcellformattingeventargs e)
            {
                if (e.rowindex != -1 && e.columnindex == 1 && e.value != null && e.value.tostring() == "")
                {
                    e.cellstyle.backcolor = color.red;
                    e.cellstyle.forecolor = color.blue;
                    e.cellstyle.selectionbackcolor = color.blueviolet;
                }
            }
      

  6.   

    gvInfo.Rows[i].Cells[5].Style.ForeColor = Color.Red;