How to position datgridview based on textbox value
Through bindingSource control, I am using LinqtoSql Products class in my datagridview, I would like to make search for a given product name, so while typing its name in a textbox, datagridview selected row should change position. I do not want to filter my list, only find the required row. How to do that please.
2 Answers
Know the answer? Post it. Somebody with the same question will find it here.

Sudhakar ChaudharyRank #1,379 · 1.2K reputationPosted Jul 29, 2012, 1:50 PM EDT
try
{
dataGridView1.ClearSelection();
for (int i = 0; i < (dataGridView1.Rows.Count); i++)
{
if dataGridView1.Rows[i].Cells[0].Value.ToString().StartsWith(textBox1.Text))
{
dataGridView1.FirstDisplayedScrollingRowIndex = i;
dataGridView1.Rows[i].Selected = true;
return;
}
}
}
catch (Exception) { }
Samio170 reputationPosted Jul 29, 2012, 2:46 PM EDT
if (dataGridView1.Rows[i].Cells[1].Value.ToString().StartsWith(textBox1.Text, true, CultureInfo.InvariantCulture))
Thank you for your valuable help.