2013-11-15 80 views
1

我有一个数据网格称为dataGridView1数据网格行,它有一个单元格中包含日期,我想基于色彩的在下面的代码中的某些行:删除基于单元格值

foreach (DataGridViewRow row in dataGridView1.Rows) 
{ 
    if ((Convert.ToDateTime(row.Cells[7].Value) - DateTime.Today).Days <= 90) 
    { 
     row.DefaultCellStyle.BackColor = Color.Green; 
    } 
} 

此代码成功上。我想要的是删除所有未着色的剩余行,该怎么做?

回答

0
for(int i=dgv.Rows.count-1;i>=0;i--) 
{ 
    if ((Convert.ToDateTime(row.Cells[7].Value) - DateTime.Today).Days <= 90) 
    { 
     row.DefaultCellStyle.BackColor = Color.Green; 
    } 
    else 
    { 
     dgv.rows.removeAt(i); 
    } 
}