Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR CSHARP

c# find value in datagridview

private void tb_Search_TextChanged(object sender, EventArgs e)
        {


            string searchValue = tb_Search.Text;
            int rowIndex = -1;
            dataGridView1.SelectionMode = DataGridViewSelectionMode.FullRowSelect;
            try
            {
                foreach (DataGridViewRow row in dataGridView1.Rows)
                {
                    if (row.Cells[0].Value.ToString().Contains(searchValue))
                    {
                        rowIndex = row.Index;
                        dataGridView1.ClearSelection();
                        row.Selected = true;
                        dataGridView1.FirstDisplayedScrollingRowIndex = rowIndex;
                        dataGridView1.Focus();
                        break;
                    }
                }
            }
            catch (Exception)
            {
                MessageBox.Show("No solutions with that name.");
}
}
}
}
Source by social.msdn.microsoft.com #
 
PREVIOUS NEXT
Tagged: #find #datagridview
ADD COMMENT
Topic
Name
4+8 =