Monday, 24 December 2012

DataGridView Search & Focusing a Search row

Solutions 1:    
private void button1_Click(object sender, EventArgs e)
{
            dataGridView1.ClearSelection();
            String searchValue = textBox1.Text;  //Textbox1 -> Search Key Word
            int rowIndex = -1;
            foreach (DataGridViewRow row in dataGridView1.Rows)
            {
                if (row.Cells[1].Value != null)
                {
                    if (row.Cells[1].Value.ToString().ToLower().Equals(searchValue.ToLower()))
                    {
                        rowIndex = row.Index;                       
                        dataGridView1.Rows[rowIndex].Selected = true;
                        dataGridView1.FirstDisplayedScrollingRowIndex = rowIndex;                       
                        break;
                    }
                }
            }
        }


No comments:

Post a Comment