Using a textbox to search a value in a given datagridview column, the code below position the selected row on the column containing the text typed.
private void textBox1_TextChanged(object sender, EventArgs e)
{
//if (Char.IsLetter(e.KeyChar))
//{
for (int i = 0; i < (productDataGridView.Rows.Count); i++)
{
if (productDataGridView.Rows[i].Cells[1].Value.ToString().StartsWith(textBox1.Text, true, CultureInfo.InvariantCulture))
{
productDataGridView.FirstDisplayedCell = productDataGridView[1, i];
productDataGridView.CurrentRow.DefaultCellStyle.BackColor = System.Drawing.Color.Red;
return; // stop looping
}
}
}
The problem is that I cannot highlight or change the back color of the required row while typing in the textbox, any help please?
Tried this solution, this finally works like a charm: