2019-11-7 seo達(dá)人
功能描述:右擊表格中對(duì)應(yīng)的行,進(jìn)行刪除或者刷新的操作。
先往DataGridView上拖一個(gè)ContextMenuStrip控件
在下面分別輸入刪除與刷新
雙擊刪除,輸入代碼:
private void 刪除ToolStripMenuItem_Click_1(object sender, EventArgs e)
{
try
{
DialogResult dr = MessageBox.Show("確定刪除嗎?", "提示", MessageBoxButtons.OKCancel);
if (dr == DialogResult.OK)
{
//獲取選中行的數(shù)據(jù)
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)
{//通過走七層查詢出數(shù)據(jù)庫(kù)中新的內(nèi)容:
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;
}
藍(lán)藍(lán)設(shè)計(jì)的小編 http://sillybuy.com