在上图中提到
朋友有如上所述的WinForm,然后在GridView中删除所选行时右键单击复选框。
感谢。
答案 0 :(得分:0)
您可以使用以下代码从GridView中删除所选行:
private void deleteButton_Click(object sender, EventArgs e)
{
gridView1.GetSelectedRows();
GridView view = gridControl1.FocusedView as GridView;
view.DeleteSelectedRows();
//DB.SubmitChanges();
}
或代码:
private void deleteButton_Click(object sender, EventArgs e)
{
GridView view = gridControl1.FocusedView as GridView;
if (view == null || view.SelectedRowsCount == 0) return;
DataRow[] rows = new DataRow[view.SelectedRowsCount];
for (int i = 0; i < view.SelectedRowsCount; i++)
rows[i] = view.GetDataRow(view.GetSelectedRows()[i]);
view.BeginSort();
try
{
foreach (DataRow row in rows)
row.Delete();
}
finally
{
view.EndSort();
}
}
您可以在循环for
中调用您的删除方法:
foreach (DataRow row in rows)
{
MyDeleteMethod(row["ColumnNameId"]);
//You must cast row["ColumnNameId"] to type of parameter
row.Delete();
}
答案 1 :(得分:0)
private void btnDelete_Click(object sender, EventArgs e)
{
GridView view = gridControl1.FocusedView as GridView;
foreach (var rowHandle in gridView1.GetSelectedRows())
{
//you have now dataRow checked for deleting from your database
DataRow dw = view.GetDataRow(rowHandle);
//This line for delete the checked rows from your Grid view
view.DeleteRow(rowHandle);
}
}
有关如何删除所选数据行的更多信息,请访问此link