ghasem deh

ghasem deh

  • NA
  • 258
  • 40.2k

how do excel find in datagridview !?

May 6 2015 8:44 AM
hi
i used this code to search in datagridview to find and select row ! (no filter)
butt, when datagrid have Repetitive value in row's ---> dont get next row !
How do I put a button to the next row with every click to Btn_find ?
(Find similar Excel)
 
 
private void button1_Click(object sender, EventArgs e)
        {
            button1.Text = "Find Next";
            {
                foreach (DataGridViewRow row in dataGridView1.Rows)
                {
                    if (row.Cells["ProductId"].Value == null)
                    {
                        continue;
                    }
                    if (row.Cells["ProductId"].Value.ToString().Trim() == textBox1.Text)
                    {
                        dataGridView1.CurrentCell = row.Cells["ProductId"];
                        dataGridView1.FirstDisplayedScrollingRowIndex = dataGridView1.Rows[row.Index].Index;
                        return;
                    }
                }
            } 
        } 

Answers (5)