在我的例子中,我有:
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;
}
任何想法如何做到这一点? 反正有可能吗?
答案 0 :(得分:0)
你可以这样使用
foreach(DataGridViewRow row in dgv.Rows)
{
if(row.Cells[someColumn].Value.ToString().Equals(someTerm))
{
dgvRow.DefaultCellStyle.BackColor = Color.Red;
}
}