0
votes

can anyone please help me for refreshing the datagridview after searching records from it. ie., the below code will select the record from the dgv when i first search a value; when I search second value in dgv it is selecting second value but still selecting first searched value also.

private void button2_Click(object sender, EventArgs e)

{

        dataGridView1.SelectionMode = DataGridViewSelectionMode.FullRowSelect;            
        try
        {         

            foreach (DataGridViewRow row in dataGridView1.Rows)
            {
                if (row.Cells["Name"].Value.ToString().ToUpperInvariant().Contains(textBox1.Text.ToUpperInvariant()))
                {                        
                    dataGridView1.Rows[row.Index].Selected = true;
                    //dataGridView1.Rows[row.Index].DefaultCellStyle.BackColor = Color.Yellow;
                    //dataGridView1.Refresh();


                }

            }                                
        }
        catch (Exception exc)
        {

        }


    }
1
got it by using dataGridView1.ClearSelection();Pravii

1 Answers

0
votes

got it by using dataGridView1.ClearSelection()