The following does not care how the DataGridView was loaded. Note I used case insensitive. For other columns follow the same logic.
namespace DataGridViewGetCellStyle
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
dataGridView1.CellFormatting += DataGridView1OnCellFormatting;
}
private readonly List<string> _firstNamesList = new List<string>() { "anne", "mary" };
private void DataGridView1OnCellFormatting(object sender, DataGridViewCellFormattingEventArgs e)
{
if (e.ColumnIndex != 0) return;
if (_firstNamesList.Contains(Convert.ToString(dataGridView1.Rows[e.RowIndex].Cells[0].Value), StringComparer.OrdinalIgnoreCase))
{
dataGridView1.Rows[e.RowIndex].DefaultCellStyle.BackColor = Color.Yellow;
e.CellStyle.Font = new Font(e.CellStyle.Font, FontStyle.Bold);
}
else
{
dataGridView1.Rows[e.RowIndex].DefaultCellStyle.BackColor = Color.Empty;
e.CellStyle.Font = new Font(e.CellStyle.Font, FontStyle.Regular);
}
}
}
}