实现如图功能:
1.添加一个contextMenuStrip到当前窗口,items为菜单内容,如添加删除
2.给dataGridView1添加右击菜单事件dataGridView1_CellMouseDown
private void dataGridView1_CellMouseDown(object sender, DataGridViewCellMouseEventArgs e)
{
joid = int.Parse(dataGridView1.Rows[e.RowIndex].Cells[0].Value.ToString());//右击改变索引
if (e.Button == MouseButtons.Right)
{
if (e.RowIndex >= 0)
{
//若行已是选中状态就不再进行设置