0

在我的示例中,我得到了:

DataTable dt = SomeMethodThatFillsDataTable();
DataGridView dgv = new DataGridView;
dgv.DataSource = dt;

现在我想从 DataTable 中“挑选”一些 DataRows 并在 DataGridView 中突出显示它

DataRow[] foundRows = dt.Select("someColumn = someTerm");

foreach (DataRow row in foundRows)    
{      
    DataGridViewRow dgvRow = // here i would like to get acces to DataGridViewRow "attached" to row    
    dgvRow.DefaultCellStyle.BackColor = Color.Red;    
}

任何想法如何做到这一点?有可能吗?

4

1 回答 1

0

你可以用这种方式

foreach(DataGridViewRow row in dgv.Rows)
{
    if(row.Cells[someColumn].Value.ToString().Equals(someTerm))
    {
        dgvRow.DefaultCellStyle.BackColor = Color.Red;
    }
}
于 2017-01-18T09:06:59.957 回答