Quantcast
Channel: Visual Studio Integrate forum
Viewing all articles
Browse latest Browse all 4410

VSPackage 2010: how to enable copy/cut/paste edit menu command

$
0
0

Hi, 
I want to enable the default copy/cut/paste menu commands when the DataGridView from my my Designer View is in focus.  However, I could not get it to work.  I looked at the other threads, and also could not find an answer to my problem.  Any help from you would be greatly appreciated.

Here is what I have:

public sealed class MyPackage: Package, IVsSelectionEvents
{
    [...]
    protected override void Initialize()
    {
        initEditMenuItems();
    }
    private void initEditMenuItems()
    {

        IMenuCommandService mcs = GetService(typeof(IMenuCommandService)) as OleMenuCommandService;
        if (null != mcs)
        {
            addCommand( mcs, StandardCommands.Copy,
                        new EventHandler(onCopy),
                        new EventHandler(onQueryCopy));

        }
    }

    private void addCommand(IMenuCommandService mcs,
                            CommandID cmdID,
                            EventHandler commandEvent,
                            EventHandler queryEvent)
    {
        OleMenuCommand command = new OleMenuCommand(commandEvent, cmdID);
        // Add an event handler to BeforeQueryStatus if one was passed in
        if (null != queryEvent)
        {
            command.BeforeQueryStatus += queryEvent;
        }

        try
        {
            // Add the command using our IMenuCommandService instance
            mcs.AddCommand(command);
        }
        catch (System.Exception)
        {
            // Menu command is already added
        }

    }

    private void onQueryCopy(object sender, EventArgs e)
    {
        OleMenuCommand command = (OleMenuCommand)sender;
        command.Enabled = true;
    }

    private void onCopy(object sender, EventArgs e)
    {

    }
}
I debuged the code, and addCommand() was called properly.  However, the copy menu is always disable.  What should I do to enable the copy menu item? 

Thanks,
Emily 



Viewing all articles
Browse latest Browse all 4410

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>