如何使得缺发这列中!=0的项变为红色字体,比如说:第二行 GPS 缺发4 我如何让其显示为红色,然后点击它,在datagridview空间下texbox中显示出来?

解决方案 »

  1.   

    if (this.dataGrid.Rows[i].Cells[j] ... 判断是否!=0)
     this.dataGrid.Rows[i].Cells[j].Style.ForeColor = Color.Red;//设置字体颜色
      

  2.   

    把文字放进textbox中,设置样式,点击后将样式还原
      

  3.   

    dataGridView1.CellFormatting +=(s,e)=>
                    {
                        int i= int.Parse(e.Value.ToString());
                        if (i!=0)
                        {
                            e.CellStyle.ForeColor = Color.Red;
                        }
                    };
      

  4.   

    我已经按照你们的提示写出如下代码:  
     for (int row = 0; row < QueryHW_DB.RowCount; row++)
      for (int column = 0; column < QueryHW_DB.ColumnCount; column++)
      //MessageBox.Show ("值是:",QueryHW_DB.Rows[3].Cells[3].Value.ToString ());
      if (Convert.ToInt16 ( QueryHW_DB.Rows[row].Cells[column].Value) !=0)
      this.QueryHW_DB.Rows[row].Cells[column].Style.ForeColor = Color.Red;
    但是有个地方 if (Convert.ToInt16 ( QueryHW_DB.Rows[row].Cells[column].Value) !=0)还是报错?
      

  5.   


     this.dataGridView1.Rows[i].Cells[validateRows[j]["COLUMN_NAME"].ToString()].Style.BackColor = Color.Red;