当我在datagridview中显示文件时,我会在目录中列出文件,点击该特定文件夹名称。现在使用上下文菜单我想在该上下文菜单中添加此sendto选项,并希望将该文件发送到任何可移动媒体。
答案 0 :(得分:2)
您在Windows“发送至”菜单中看到的程序快捷方式存储在%APPDATA%\Microsoft\Windows\SendTo
文件夹中。
阅读此文件夹的内容并在Grid的上下文菜单中显示选项。
快捷方式是.LNK
个文件。从LNK文件中解析EXE的名称,并使用System.Diagnostics.Process.Run
以下是如何从LNK文件中解析EXE位置
答案 1 :(得分:0)
尝试修改此示例,它在不同的列上启用不同的选项:
//Define different context menus for different columns
private ContextMenu contextMenuForColumn1 = new ContextMenu();
private ContextMenu contextMenuForColumn2 = new ContextMenu();
Add the following line of code in the form load event:
private void Form_Load(object sender, EventArgs e)
{
// Load all default values of controls
populateDataGridView();
// Add context mneu items
contextMenuForColumn1.MenuItems.Add("Make Active", new EventHandler(MakeActive));
contextMenuForColumn2.MenuItems.Add("Delete", new EventHandler(Delete));
contextMenuForColumn2.MenuItems.Add("Register", new EventHandler(Register));
}
Add the following code to mouseup event of the gridview:
private void dataGridView_MouseUp(object sender, MouseEventArgs e)
{
// Load context menu on right mouse click
DataGridView.HitTestInfo hitTestInfo;
if (e.Button == MouseButtons.Right)
{
hitTestInfo = dataGridView.HitTest(e.X, e.Y);
// If column is first column
if (hitTestInfo.Type == DataGridViewHitTestType.Cell && hitTestInfo.ColumnIndex == 0)
contextMenuForColumn1.Show(dataGridView, new Point(e.X, e.Y));
// If column is second column
if (hitTestInfo.Type == DataGridViewHitTestType.Cell && hitTestInfo.ColumnIndex == 1)
contextMenuForColumn2.Show(dataGridView, new Point(e.X, e.Y));
}
}
关于SO的类似问题: