110,534
社区成员
发帖
与我相关
我的任务
分享
private void button1_Click(object sender, EventArgs e)
{
string name =TextBox1.Text;//设置的查询条件,如果多条件,在后面继续添加
foreach (DataGridViewRow item in dataGridView1.Rows)
{
if (item.Selected == true) //设置如果条件不符合时 取消选中行
{
item.Selected = false;
}
if (name != "")
{
if (item.Cells["name"].Value.ToString() == name)
{
dataGridView1.CurrentCell = item.Cells[0]; //设置光标(第一行的箭头)是否为选中行
textbox1.text=item.Cells[0].Value.ToString();//要显示那个字段的信息就设置那个
return;
}
}
}
}