1

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.

4

2 に答える 2

2

Windows の「送る」メニューに表示されるプログラムへのショートカットは、%APPDATA%\Microsoft\Windows\SendToフォルダーに保存されます。

このフォルダーの内容を読み取り、グリッドのコンテキスト メニューにオプションを表示します。

ショートカットは.LNKファイルです。LNK ファイルから EXE の名前を解決し、次を使用して EXE を呼び出します。System.Diagnostics.Process.Run

LNK ファイルから EXE の場所を解決する方法は次のとおりです。

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

于 2012-06-22T05:08:25.150 に答える
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に関する同様の質問:

于 2012-06-22T05:03:57.543 に答える