DataGridView右键菜单/复制示例? [英] DataGridView right-click menu/copy example?

查看:1088
本文介绍了DataGridView右键菜单/复制示例?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的表单上有一个DataGridView(dgv1)。在特定单元格中,我希望用户能够右键单击并选择COPY将单元格的内容复制到剪贴板。

I have a DataGridView (dgv1) on my form. In a particular cell, I'd like for the user to be able to right-click and choose "COPY" to copy the contents of the cell to the clipboard. Can anyone point me in the direction of a tutorial or site that shows how to accomplish this in C#?

谢谢!

推荐答案

您可以使用ContextMenuStrip来完成此任务。
(或VS2k5之前的上下文菜单)

You can use ContextMenuStrip to accomplish this. (Or ContextMenu for pre-VS2k5)

本文摘录:

ContextMenuStrip mnu = new ContextMenuStrip();
ToolStripMenuItem mnuCopy = new ToolStripMenuItem("Copy");
ToolStripMenuItem mnuCut = new ToolStripMenuItem("Cut");
ToolStripMenuItem mnuPaste = new ToolStripMenuItem("Paste");
//Assign event handlers
mnuCopy.Click += new EventHandler(mnuCopy_Click);
mnuCut.Click += new EventHandler(mnuCut_Click);
mnuPaste.Click += new EventHandler(mnuPaste_Click);
//Add to main context menu
mnu.Items.AddRange(new ToolStripItem[] { mnuCopy, mnuCut, mnuPaste});
//Assign to datagridview
dataGridView1.ContextMenuStrip = mnu;

有关上述链接的更多信息。

There is more information on the above link.

这篇关于DataGridView右键菜单/复制示例?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆