DataGridView在判定datatable后,如何根据datatable不同的行状态,显示不同的背景色

解决方案 »

  1.   

    需要自己重写DataGridView控件的onPain~~里面写个
     
    for()
    {
      switch()
      {
         g.drawline();
       }
    }这样结构的东西
      

  2.   

    http://topic.csdn.net/u/20070429/09/a56dfb14-96bc-4bfe-bd69-652cc24df3de.html
      

  3.   

    上面的方法不行。我是根据datatable不同的行状态,显示不同的背景色,不是根据值。问题就是如何得到行的状态。除非不用判定的方法。只能用一行一行的往DataGridView里加才行
      

  4.   

    根据datatable的行状态,进行判断,设置datagridview的背景色
      

  5.   

    在GridView里的RowDataBound()事件里循环datatable的不同状态把GridView每行的颜色绑上
      

  6.   

    DataGridView在判定datatable后,如何根据datatable不同的行状态,显示不同的背景色哪些状态?要这个效果还是?
    如何设置选中行的背景颜色和字体颜色?
    dataGridView1.DefaultCellStyle.SelectionBackColor = Color.Transparent;
    dataGridView1.DefaultCellStyle.SelectionForeColor = Color.Red;
      

  7.   

    dataGridView1[0, 1].Style.Font = new Font("Tahoma", 15); //字体
    dataGridView1[0, 1].Style.ForeColor = Color.Red; //颜色
      

  8.   

    datatable行状态都不明白吗?
    上面的方法都不行。
    RowDataBound()我怎么找不到这个事件
      

  9.   

    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;
      }
      }

    DataGridViewCellStyle   style   =   new   DataGridViewCellStyle(); 
    foreach(DataGridViewRow   aRow   in   dataGridView1.Rows) 

    if(aRow.Cells[0].Value.ToString().Equals(""))

    style.BackColor=Color.Blue; 
    aRow.DefaultCellStyle=style; 

    }
      

  10.   

    datatable行状态  
    这个不是属性或事件,请先用别人能听懂的方法解释你的需求
      

  11.   

    有一个row.state吧,然后foreach根据不同的状态,设定dgv行。
      

  12.   

    可以在CellFormatting中判定对应的数据的行状态,设置单元格样式
    private void dataGridView1_CellFormatting(object sender, DataGridViewCellFormattingEventArgs e)
    {
    DataTable dt = (DataTable)dataGridView1.DataSource;
    if (e.RowIndex >= dt.Rows.Count || e.RowIndex < 0)
    {
    return;
    }
    DataRowState state = dt.DefaultView[e.RowIndex].Row.RowState;
    switch (state)
    {
    case DataRowState.Added: e.CellStyle.BackColor = Color.Red; break;
    case DataRowState.Modified: e.CellStyle.BackColor = Color.Yellow; break;
    case DataRowState.Unchanged: break;
    }
    }
      

  13.   

    可以在datatable检测状态里加一事件委托,满足更改条件则发出这个事件,委托函数为更改datagridview的行背景色。