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.
Sudhakar ChaudharyPosted Jul 29, 2012, 5:50 PM
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) { }
SamioPosted Jul 29, 2012, 6:46 PM
if (dataGridView1.Rows[i].Cells[1].Value.ToString().StartsWith(textBox1.Text, true, CultureInfo.InvariantCulture))
Thank you for your valuable help.