更新时间:2023-12-05 11:10:46
此代码删除dataGridView1的所选项目:private void btnDelete_Click( object sender,EventArgs e)
{
foreach (DataGridViewRow item in this .dataGridView1.SelectedRows)
{
dataGridView1.Rows.RemoveAt(item.Index);
}
}
还看看 -
CodeProject [ ^ ]
删除所选行中的datagridview-in-c [ ^ ]
如何去除的选择的行式数据,网格视图-C-Sharp.aspx [ ^ ]
I am trying to delete a selected row in the gridview, the User has a option of selecting the row to be deleted and he can delete only one row at a time. How can this be done.
Under the .CS page i have written the following code.
protected void gdvData_RowDeleting(object sender, GridViewDeleteEventArgs e)
{
InBoundDataBO obj = new InBoundDataBO();
int SUPPLIER_NUMBER = Convert.ToInt32(gdvData.Rows[e.RowIndex].Cells[4].Text);
string SOURCE_ENTITY = gdvData.Rows[e.RowIndex].Cells[2].Text.ToString();
string PLANT_CODE = gdvData.Rows[e.RowIndex].Cells[3].Text.ToString();
string SUPPLIER_GROUP_NUMBER = gdvData.Rows[e.RowIndex].Cells[5].Text.ToString();
obj.DeleteSupplierDetails(SUPPLIER_NUMBER, SOURCE_ENTITY, PLANT_CODE, SUPPLIER_GROUP_NUMBER);
}
Under the Data Acess Layer i have written the following method.
public static void DeleteSupplierDetails(String R1, String R2, String R3, String R4,out String message)
{
message = String.Empty;
Database db = Helper.CreateDatabase();
DbCommand cmd = db.GetStoredProcCommand("PDSS_STAGING_DEV.Delete_SupplierDetails");
cmd.CommandType = CommandType.StoredProcedure;
db.AddInParameter(cmd, "P_SOURCE_ENTITY", DbType.String, R1);
db.AddInParameter(cmd, "P_PLANT_CODE", DbType.String, R2);
db.AddInParameter(cmd, "P_SUPPLIER_NUMBER", DbType.String, R3);
db.AddInParameter(cmd, "P_SUPPLIER_GROUP_NUMBER", DbType.String, R4);
db.AddOutParameter(cmd,"P_RETURN_MSG", DbType.String,10);
db.ExecuteNonQuery(cmd);
message = cmd.Parameters["P_RETURN_MSG"].Value.ToString().Trim();
}
This code removes selected items of dataGridView1:private void btnDelete_Click(object sender, EventArgs e) { foreach (DataGridViewRow item in this.dataGridView1.SelectedRows) { dataGridView1.Rows.RemoveAt(item.Index); } }
Also have a look at-
CodeProject[^]
Removing-selected-rows-in-a-datagridview-in-c[^]
How-to-remove-selected-row-in-data-grid-view-C-Sharp.aspx[^]