Click here to Skip to main content
16,018,158 members
Please Sign up or sign in to vote.
1.40/5 (2 votes)
See more:
In my windows application i have a data grid view. There are some dropdowns and buttons. According to user's selection data grid view will be full with data.. ow i want search option for that data when user type some words in text box and after that datagrid view should display records related to it.
please help me
Posted
Comments
Jameel VM 1-Aug-13 1:10am    
did you try anything?

1 solution

Why you are using row.Cells[row.Index]. You need to specify index of column you want to search (Problem #2). For example, you need to change row.Cells[row.Index] to row.Cells[2] where 2 is index of your column:

private void btnSearch_Click(object sender, EventArgs e)
{
string searchValue = textBox1.Text;

dgvProjects.SelectionMode = DataGridViewSelectionMode.FullRowSelect;
try
{
foreach (DataGridViewRow row in dgvProjects.Rows)
{
if (row.Cells[2].Value.ToString().Equals(searchValue))
{
row.Selected = true;
break;
}
}
}
catch (Exception exc)
{
MessageBox.Show(exc.Message);
}
}
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900