Datagridview加右键菜单功能

Datagridview加右键菜单功能
private void contextMenuStrip1_ItemClicked(object sender, ToolStripItemClickedEventArgs e)
        {
            for (int i = 0; i < contextMenuStrip1.Items.Count; i++)
            {
                if (contextMenuStrip1.Items[i].Selected)
                {
                    if (contextMenuStrip1.Items[i].Text.Trim() == "新增")
                    {
                        MessageBox.Show("执行新增操作");
                    }
                    else if (contextMenuStrip1.Items[i].Text.Trim() == "删除")
                    {
                        MessageBox.Show("执行删除操作");
                    }
                }
            }
        }



你可能感兴趣的:(Datagridview加右键菜单功能)