3个回答
展开全部
首先在程序中添加一个ContexMenuStrip1控件,给该控件添加删除项,
把 datagridview的ContexMenuStrip属性项绑定为你所添加的ContexMenuStrip1控件,然后就是你自己编写程序来操作删除具体的东西了
把 datagridview的ContexMenuStrip属性项绑定为你所添加的ContexMenuStrip1控件,然后就是你自己编写程序来操作删除具体的东西了
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
在MouseDown 事件里面写:
private void KnowledgedataGridView_MouseDown(object sender, MouseEventArgs e)
{
if (e.Button == MouseButtons.Right) //判断是不是右键
{
Control control = new Control();
Point ClickPoint = new Point(e.X, e.Y);
control.GetChildAtPoint(ClickPoint);
if (KnowledgedataGridView.HitTest(e.X, e.Y).RowIndex >= 0 && KnowledgedataGridView.HitTest(e.X, e.Y).ColumnIndex >= 0)//判断你点的是不是一个信息行里
{
KnowledgedataGridView.CurrentCell = KnowledgedataGridView.Rows[KnowledgedataGridView.HitTest(e.X, e.Y).RowIndex].Cells[KnowledgedataGridView.HitTest(e.X, e.Y).ColumnIndex];
ContextMenu con = new ContextMenu();
MenuItem menuAddknowledge = new MenuItem("添加知识点");
MenuItem menuLine1 = new MenuItem("-");
MenuItem menuUpdateknowledge = new MenuItem("修改修改知识点");
MenuItem menuLine2 = new MenuItem("-");
MenuItem menuDeleteknowledge = new MenuItem("删除知识点");
menuAddknowledge.Click += new EventHandler(tSButAdd_Click);
menuUpdateknowledge.Click += new EventHandler(tSButUpdate_Click);
menuDeleteknowledge.Click += new EventHandler(tSButDel_Click);
con.MenuItems.Add(menuAddknowledge);
con.MenuItems.Add(menuLine1);
con.MenuItems.Add(menuUpdateknowledge);
con.MenuItems.Add(menuLine2);
con.MenuItems.Add(menuDeleteknowledge);
this.KnowledgedataGridView.ContextMenu = con;
con.Show(KnowledgedataGridView, new Point(e.X + 10, e.Y));
}
}
}
private void KnowledgedataGridView_MouseDown(object sender, MouseEventArgs e)
{
if (e.Button == MouseButtons.Right) //判断是不是右键
{
Control control = new Control();
Point ClickPoint = new Point(e.X, e.Y);
control.GetChildAtPoint(ClickPoint);
if (KnowledgedataGridView.HitTest(e.X, e.Y).RowIndex >= 0 && KnowledgedataGridView.HitTest(e.X, e.Y).ColumnIndex >= 0)//判断你点的是不是一个信息行里
{
KnowledgedataGridView.CurrentCell = KnowledgedataGridView.Rows[KnowledgedataGridView.HitTest(e.X, e.Y).RowIndex].Cells[KnowledgedataGridView.HitTest(e.X, e.Y).ColumnIndex];
ContextMenu con = new ContextMenu();
MenuItem menuAddknowledge = new MenuItem("添加知识点");
MenuItem menuLine1 = new MenuItem("-");
MenuItem menuUpdateknowledge = new MenuItem("修改修改知识点");
MenuItem menuLine2 = new MenuItem("-");
MenuItem menuDeleteknowledge = new MenuItem("删除知识点");
menuAddknowledge.Click += new EventHandler(tSButAdd_Click);
menuUpdateknowledge.Click += new EventHandler(tSButUpdate_Click);
menuDeleteknowledge.Click += new EventHandler(tSButDel_Click);
con.MenuItems.Add(menuAddknowledge);
con.MenuItems.Add(menuLine1);
con.MenuItems.Add(menuUpdateknowledge);
con.MenuItems.Add(menuLine2);
con.MenuItems.Add(menuDeleteknowledge);
this.KnowledgedataGridView.ContextMenu = con;
con.Show(KnowledgedataGridView, new Point(e.X + 10, e.Y));
}
}
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询