private void DataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e) { if (dataGridView1.Columns[e.ColumnIndex].Name == "colBtn_drop") { Material model = new Material(); model.Id = Convert.ToInt32(dataGridView1.Rows[e.RowIndex].Cells["id"].Value); if (MaterialHelper.Drop(model, new List <string>() { "id" })) { ShowDataGird(); MessageBox.Show("删除成功", "", MessageBoxButtons.OK, MessageBoxIcon.Information); } } if (dataGridView1.Columns[e.ColumnIndex].Name == "colBtn_alter") { Material model = new Material(); model.Id = Convert.ToInt32(dataGridView1.Rows[e.RowIndex].Cells["Id"].Value); model.sum = Convert.ToInt32(dataGridView1.Rows[e.RowIndex].Cells["sum"].Value); model.name = dataGridView1.Rows[e.RowIndex].Cells["name"].Value.ToString(); model.Price = dataGridView1.Rows[e.RowIndex].Cells["Price"].Value.ToString(); if (MaterialHelper.AlterByPK(model, "id")) { ShowDataGird(); MessageBox.Show("修改成功", "", MessageBoxButtons.OK, MessageBoxIcon.Information); } } }