ContextMenu: lock to one gridview (on tabcontrol page) + hide items

Ask questions about creating Graphical User Interfaces (GUI) in PowerShell and using WinForms controls.
Forum rules
Do not post any licensing information in this forum.

Any code longer than three lines should be added as code using the 'Select Code' dropdown menu or attached as a file.
Locked
User avatar
stevens
Posts: 382
Meble kuchenne na zamówienie - na wymiar - Wrocław
Joined: Wed Jun 15, 2016 2:26 am

ContextMenu: lock to one gridview (on tabcontrol page) + hide items

Post by stevens »

Hi,

I have a Powershell Studio Form with tabcontrol in the main form.
In the tabcontrol there are several different gridviews (every tab -3 tabs- has one). On one of these gridviews there is a contextmenustrip active, which works fine.

No I needed another contextmenustrip for another gridview in another tab and saw that my contextmenustrip is active wherever I click in the form instead of locked to 1 gridview.

My question:
-how can I lock the contextmenu to 1 gridview in 1 tab (it should only appear there when rightclicking an item in that gridview)?
-how can I add another contextmenu that is 'locked' (appears only) on another gridview (other tab)
-can I hide specifc contexmenuitems for specific users if ($env:username) –eq .. then remove item or disable?
Note: I'm already hiding tabs using $Mytab = $tabcontrolMainForm.TabPages['Mytab']
if ... {$tabcontrolMainForm.TabPages.Remove($Mytab )} which works fine. Is there a similar approach to hide contextmenuitems?


Thanks!
J.

jvierra
Posts: 14213
Joined: Tue May 22, 2007 9:57 am
Contact:

Re: ContextMenu: lock to one gridview (on tabcontrol page) + hide items

Post by jvierra »

The context menustrip must be attached to the gridview and not the tab control or the tab page.

User avatar
stevens
Posts: 382
Joined: Wed Jun 15, 2016 2:26 am

Re: ContextMenu: lock to one gridview (on tabcontrol page) + hide items

Post by stevens »

Thanks for your quick reply!
Yes, exactly, but I can't find a way to change the way it is attached now to the gridview.
Also, any idea to hide a control in the context menu strip?

jvierra
Posts: 14213
Joined: Tue May 22, 2007 9:57 am
Contact:

Re: ContextMenu: lock to one gridview (on tabcontrol page) + hide items

Post by jvierra »

No idea what you mean. Just remove the contextmenu reference from the datagridview control in properties in the designer.

User avatar
stevens
Posts: 382
Joined: Wed Jun 15, 2016 2:26 am

Re: ContextMenu: lock to one gridview (on tabcontrol page) + hide items

Post by stevens »

Thanks, didn't know there was a property contexmenustrip :-)

Locked