How I can use windows's SendTo option in my C# Application using datagridview

余生颓废 提交于 2020-01-05 12:23:30

问题


i am listing files from directories on click on that specific folder name, when files show in datagridview. Now using context menu i want to add this sendto option in that context menu and want to send that file to any removable media.


回答1:


The shortcuts to programs that you see in windows 'send-to' menu are stored in %APPDATA%\Microsoft\Windows\SendTo folder.

Read the contents of this folder and show the options in your Grid's context menu.

The shortcuts are .LNK files. Resolve the name of the EXE from the LNK file and call the EXE using System.Diagnostics.Process.Run

Here is how you can resolve the EXE location from the LNK files

http://social.msdn.microsoft.com/Forums/en-US/csharpgeneral/thread/8d0f33a3-af4d-498f-a37b-e6fc84136c4a/




回答2:


try to midify this example, it enables different options on different columns:

//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));
    }
} 

Similar questions on SO:

  • Add context menu in a datagrid view in a winform application
  • right click context menu for datagridview


来源:https://stackoverflow.com/questions/11150412/how-i-can-use-windowss-sendto-option-in-my-c-sharp-application-using-datagridvi

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!