Selecting Row in a DataGrid from a search. W#

2

Good afternoon, Does anyone have a code where I can select a Row in a DataGrid , from a search?

Where I make my Button_Click to a TextBox with a certain value, doing the search in DataGridView , thus selecting the Row for that value of TextBox .     

asked by anonymous 18.08.2016 / 21:30

1 answer

4

You can cycle through the rows of DataGrid and compare the values with the text of TextBox .

string pesquisar = textBox1.Text.ToLower();

dataGridView1.ClearSelection();

foreach (DataGridViewRow row in dataGridView1.Rows)
{
    if (row.Cells["NomeDaColuna"].Value != null)
    {
        if (row.Cells["NomeDaColuna"].Value.ToString().ToLower().Equals(pesquisar))
        {
            row.Selected = true;
            break;
        }
    }
}
    
18.08.2016 / 21:45