[英]Delete selected row from DataGridView
I need to delete the selected row from my DataGridView. 我需要从DataGridView中删除选定的行。 Currently I managed to execute the select command but i do not know with what code to continue to remove/delete the selected row. 目前,我设法执行了select命令,但是我不知道该用什么代码来继续删除/删除所选行。
The code that i use is : 我使用的代码是:
(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
//...
}
Where: - refTofrPlanMain represents a reference to Form1 (I am working in Form2) - dGVPlan is the DataGridView. 其中:-refTofrPlanMain表示对Form1的引用(我在Form2中工作)-dGVPlan是DataGridView。
Thank you for your support. 谢谢您的支持。
(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.