datagridview
how to find a particular value from datagridview when it is connected to a database
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Kirtan PatelPosted Sep 4, 2009, 10:54 AM
Here is What you want
it will Search The DataGridView and Tell you in Which Row it is Located :)
dont forget to mark "Do you like answer" please it will give me some credits :)
private void btnSearch_Click(object sender, EventArgs e)
{
bool Found = false;
int FoundRowIndex=0 , FoundColIndex=0 ;
string SearchText = txtSearch.Text.Trim();
foreach (DataGridViewRow r in dataGridView1.Rows)
{
if (Found == false)
{
int rindex = r.Index;
int columnCount = dataGridView1.Columns.Count-1;
for (int i = 0; i < columnCount; i++)
{
if (dataGridView1.Rows[rindex].Cells[i].Value.ToString() == SearchText)
{
FoundRowIndex = r.Index;
FoundColIndex = i;
Found = true;
}
}
}
else
{
break;
}
}
if (Found == true)
{
MessageBox.Show("Found at Row =" + FoundRowIndex);
}
else
{
MessageBox.Show("Value Not Found");
}
}
Roei BarPosted Sep 4, 2009, 7:58 AM
hope this helps