[英]Delete selected row from DataGridView
我需要从DataGridView中删除选定的行。 目前,我设法执行了select命令,但是我不知道该用什么代码来继续删除/删除所选行。
我使用的代码是:
(refTofrPlanMain.dGVPlan.DataSource as DataTable).DefaultView.RowFilter = string.Format("Vodic = '{0}'", searchTBoxW.Text);
foreach (DataGridViewRow item in refTofrPlanMain.dGVPlan.Rows)
{
if (item.Visible)
{
item.Selected = true;
break;
}
//...
//Other code
//...
}
其中:-refTofrPlanMain表示对Form1的引用(我在Form2中工作)-dGVPlan是DataGridView。
谢谢您的支持。
(refTofrPlanMain.dGVPlan.DataSource as DataTable).DefaultView.RowFilter = string.Format("Vodic = '{0}'", searchTBoxW.Text);
for(int i=refTofrPlanMain.dGVPlan.Rows.Count-1; i >=0; i--)
{
DataGridViewRow item = refTofrPlanMain.dGVPlan.Rows[i];
if (item.Visible && !item.IsCurrentRowDirty())
{
refTofrPlanMain.dGVPlan.Rows.RemoveAt(i);
break;
}
//...
//Other code
//...
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.