如何在单击C#按钮后从DataGridView等于textbox.Text中选择一行?还有其他解决方案吗?
private void btnChk(object sender, EventArgs e)
{
for (int i = 0; i < dgv.Rows.Count; i++)
{
if (dgv.Rows[i].Cells[1].Value.ToString()==txtName.Text)
{
dgv.CurrentCell = dgv.Rows[i].Cells[1];
}
}
}
答案 0 :(得分:1)
您也可以
private void btnChk(object sender, EventArgs e)
{
for (int i = 0; i < dgv.Rows.Count; i++)
{
if (dgv.Rows[i].Cells[1].Value.ToString()==txtName.Text)
{
dgv.Rows[i].Cells[1].Selected = true;
}
}
}
答案 1 :(得分:1)
也是答案
private void btnChk(object sender, EventArgs e)
{
for (int i = 0; i < dgv.Rows.Count; i++)
{
if (dgv.Rows[i].Cells["Name"].Value.ToString()==txtName.Text)
{
dgv.Rows[i].Cells["Name"].Selected = true;
}
}
}