2019-11-7 seo达人
功能描述:右击表格中对应的行,进行删除或者刷新的操作。
先往DataGridView上拖一个ContextMenuStrip控件
在下面分别输入删除与刷新
双击删除,输入代码:
private void 删除ToolStripMenuItem_Click_1(object sender, EventArgs e)
{
try
{
DialogResult dr = MessageBox.Show("确定删除吗?", "提示", MessageBoxButtons.OKCancel);
if (dr == DialogResult.OK)
{
//获取选中行的数据
Facade.FoodMenuCateFaçade façade = new Facade.FoodMenuCateFaçade();
Entity.T_FoodMenuCate t_Food = new Entity.T_FoodMenuCate();
t_Food.CateName = dataFood.CurrentRow.Cells[1].Value.ToString();
int list1 = façade.DeleteFoodMenu(t_Food);
frmTips f = frmTips.GetInstance("删除完成");
f.Show();
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
双击刷新,输入代码:
private void 刷新ToolStripMenuItem_Click(object sender, EventArgs e)
{//通过走七层查询出数据库中新的内容:
Facade.FoodMenuCateFaçade façade = new Facade.FoodMenuCateFaçade();
Entity.T_FoodMenuCate t_Food = new Entity.T_FoodMenuCate();
List<Entity.T_FoodMenuCate> list = façade.SelectFoodMenu(t_Food);
//把值赋给表格
dataFood.DataSource = list;
}