您好,我需要帮助... [英] Hello, I need help about ..

查看:110
本文介绍了您好,我需要帮助...的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

private void dataGridView1_CellFormatting(object sender ,DataGridViewCellFormattingEventArgs e)

        {


private void dataGridView1_CellFormatting(object sender, DataGridViewCellFormattingEventArgs e)
        {


DateTime hora2 = Convert.ToDateTime(textBox2.Text);

         试试
          {

              var row = dataGridView1.Rows [e.RowIndex];



              if(Convert.ToDateTime(row.Cells [" fechhora"]。Value)> = hora2)

              {

                  e.CellStyle.ForeColor = Color.White;

                  e.CellStyle.BackColor = Color.Red;

              }¥b $ b          }¥b $ b          catch(例外情况)

          {

              MessageBox.Show(ex.Message);

          }

DateTime hora2 = Convert.ToDateTime(textBox2.Text);
          try
          {
              var row = dataGridView1.Rows[e.RowIndex];

              if (Convert.ToDateTime(row.Cells["fechhora"].Value) >= hora2)
              {
                  e.CellStyle.ForeColor = Color.White;
                  e.CellStyle.BackColor = Color.Red;
              }
          }
          catch (Exception ex)
          {
              MessageBox.Show(ex.Message);
          }


}




victor jamanca

victor jamanca

推荐答案

您好,

比较您可以使用的两个数据时间
DateTime.Compare Method(DateTime,DateTime)。


Compare two datatime you can use DateTime.Compare Method (DateTime, DateTime).

    private void dataGridView1_CellFormatting(object sender, DataGridViewCellFormattingEventArgs e)
        {
            DateTime d = DateTime.Now;
            var row = dataGridView1.Rows[e.RowIndex];
            //Target to the specified column
            if (dataGridView1.Columns[e.ColumnIndex].Name.ToString()== "CreatTime")
            {
                //Target to the specified cell
                if (DateTime.Compare(Convert.ToDateTime(row.Cells[e.ColumnIndex].Value), d) > 0)
                {
                    e.CellStyle.ForeColor = Color.White;
                    e.CellStyle.BackColor = Color.Red;
                }
            }          
        }

希望它对您有所帮助。

最好的问候,

Bob

Bob





这篇关于您好,我需要帮助...的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆