Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
220
Creating a context menu on Ultragrid in WinForms
posted

Hi,

  I am using VS2010 with Infragistics NetAdvantage 10.3 Win CLR2x to build a program.  I've got an ultragrid and I want to put a right click context menu in the grid.

I looked through about 20 posts on this subject, and non have helped in the least.  I've found 2 projects on this site that supposedly show an example -- neither of them compile.

At one point, I *think* I found something called an UltraContextMenu control in the NetAdvantage tool box.  I added it to my UltraGrid control (because, of course, a standard contextmenu strip can't be dropped onto Ultragrid) and tried to get it to work.  I couldn't, so I deleted it from the Ultragrid control.

From that point on, I've never been able to find that control in the NetAdvantage toolox again.  It has completely disappeared.  Now I'm beginning to think I mistakenly dropped some other control on the grid and that was why I couldn't get it to work.

Interestingly, if I click on the UltraGrid control in design view, I can find the ContextMenuStrip field (ditto if I click on the Start button for grid designer), but I can't edit it, or set it to anything.

Ultimately, what I'm trying to do is SO simple, that I'm wondering if I've missed something very basic.  I just want to select some rows in the grid (which I can do), right click and allow the user to select Copy from the context menu.  At the moment, if they just do a ctrl-c, they copy all the selected rows to the clip board.

I've got this bit of code here:
 myUltraGrid.ContextMenuStrip  = new ContextMenuStrip();
 myUltraGrid.ContextMenuStrip.Items.Add("Copy");

And that actually creates the menu with the correct menu item in it (meaning only "Copy"), but I have no idea how to fire off an event, or catch an event that will allow me to take advantage of that.

Any help would be appreciated.

Thanks

Parents
  • 23930
    Offline posted

    Hi,

    Thank you for contacting Infragistics Developer Support.

    What you could do after assigning the ContextMenuStrip and adding the items you need is to subscribe to the ItemClicked event of the ContextMenuStrip. In it you could use a switch statement based on the text of the items and use the PerformAction(UltraGridAction.Copy) method of the UltraGrid in order to copy the cells. You can also use PerformAction(UltraGridAction.Paste) in order to paste them. Additionally you will have to allow multi cell operation using:

    ultraGrid1.DisplayLayout.Override.AllowMultiCellOperations = AllowMultiCellOperation.Copy

                    | AllowMultiCellOperation.Paste;

    This will create a simple copy/paste functionality in your grid.

    I have attached a sample in VS2010 with NA 10.3 demonstrating the approach.

    Please let me know if you have any additional questions.

    WG_CreateContextMenu.zip
Reply Children
No Data