废话不多说直接附上代码:
for (int i = 0; i < dgv_languagePack.Rows.Count; i++)
{
if (dgv_languagePack.Rows[i].Cells[0].Value != null)
{
if ((dgv_languagePack.Rows[i].Cells[0].Value.ToString().ToUpper().IndexOf(this.txt_name.Text.ToUpper())) > -1) //.ToUpper()全部转换成大写
{
//找到匹配行
this.dgv_languagePack.Rows[i].DefaultCellStyle.BackColor = System.Drawing.Color.Yellow;
}
else
{
// 恢复之前行的背景颜色为默认的白色背景
this.dgv_languagePack.Rows[i].DefaultCellStyle.BackColor = System.Drawing.Color.White;
}
}
}