views:

54

answers:

1

I use this to look for values in my DataGridView:

private void fndBtn_Click(object sender, EventArgs e)
        {
            BindingSource src = new BindingSource();
            src.DataSource = dataGridView1.DataSource;

            src.Position = src.Find("p_Name", textBox1.Text);
        }

But I've two issues. First when I look for item that doesn't exist in my dgv, position returns 0 which is by default the first row. I don't want that, and if I verified using If statement I'll lose position 0, thus losing the first row.

Second is I want the row header be focused on and item found be highlighted. How is that possible?.

A: 

Use dataGridView's binding source like this:

//myBindingSource = dataGridView1.DataSource;
myBindingSource.Position = myBindingSource.Find("p_Name", textBox1.Text);
Jacob Seleznev