Purchase Order - disable right-click insert  Topic is solved

Discussions relating to Jiwa 7 plugin development, and the Jiwa 7 API.

Purchase Order - disable right-click insert

Postby neil.interactit » Wed Nov 04, 2015 2:30 pm

Hi guys,

Sorry for the questions storm!

I have a requirement to prevent purchase order line item modification but still allow set/clear a flag per row (for subsequent processing). I have this all working. Due to the need to still monitor PurchaseOrderForm_LinesJiwaGrid_CellClick, I couldn't toggle the .Enabled property, so instead I have been able to lock the columns ...
Code: Select all
        Dim grid = DirectCast(_purchaseOrderForm.MainUltraTabControl.Tabs("Order").TabPage.Controls.Item("LinesJiwaGrid"), JiwaGrid)
        For Each col As Column In grid.ActiveSheet.Columns
            If Not col.Tag.ToString().StartsWith("UserDefined") Then grid.LockColumn(lock, col.Tag)
        Next

This all works well, but I still need to disable the right-click row insert functionality ...
insert.png
insert.png (3.74 KiB) Viewed 5252 times

I can't quite see how to do this?

Cheers,
Neil
neil.interactit
Kohai
Kohai
 
Posts: 232
Joined: Wed Dec 03, 2014 2:36 pm
Topics Solved: 6

Re: Purchase Order - disable right-click insert

Postby Scott.Pearce » Wed Nov 04, 2015 3:27 pm

See if the grid has a ContextMenuStrip property. If it does, set it to Nothing. This *may* work. Let me know.
Scott Pearce
Senior Analyst/Programmer
Jiwa Financials
User avatar
Scott.Pearce
Senpai
Senpai
 
Posts: 765
Joined: Tue Feb 12, 2008 11:27 am
Location: New South Wales, Australia
Topics Solved: 230

Re: Purchase Order - disable right-click insert

Postby neil.interactit » Wed Nov 04, 2015 4:39 pm

No go. I tried both:
Code: Select all
        grid.ContextMenuStrip = Nothing
        grid.ContextMenu = Nothing

The right-click still works.
neil.interactit
Kohai
Kohai
 
Posts: 232
Joined: Wed Dec 03, 2014 2:36 pm
Topics Solved: 6

Re: Purchase Order - disable right-click insert

Postby Scott.Pearce » Wed Nov 04, 2015 4:41 pm

Dang. We must use a special context menu control separate from the grid. Standby, I'll go find it.
Scott Pearce
Senior Analyst/Programmer
Jiwa Financials
User avatar
Scott.Pearce
Senpai
Senpai
 
Posts: 765
Joined: Tue Feb 12, 2008 11:27 am
Location: New South Wales, Australia
Topics Solved: 230

Re: Purchase Order - disable right-click insert

Postby Scott.Pearce » Wed Nov 04, 2015 4:48 pm

You can get at it thus:

Code: Select all
_purchaseOrderForm.LinesGridControlContextMenuStrip


It's a standard windows forms context menu, but it's declared as a property of the form rather than the grid (probably because we needed finer control over when it is/isn't displayed).

So, you can mess with it (i.e disable items), but if you want to stop the thing from showing completely, it may in fact be easier to simply remove the LinesJiwaGrid CellClick handler:

Code: Select all
RemoveHandler _purchaseOrderForm.LinesJiwaGrid.CellClick, AddressOf _purchaseOrderForm.LinesJiwaGrid_CellClick


You would of course do this in Form Setup. The CellClick on this particular grid does nothing but organise and then show the context menu.
Scott Pearce
Senior Analyst/Programmer
Jiwa Financials
User avatar
Scott.Pearce
Senpai
Senpai
 
Posts: 765
Joined: Tue Feb 12, 2008 11:27 am
Location: New South Wales, Australia
Topics Solved: 230

Re: Purchase Order - disable right-click insert

Postby neil.interactit » Tue Nov 10, 2015 4:15 pm

Thanks.

This is where I ended up ...
Code: Select all
    Private _linesGridControlContextMenuStrip As ContextMenuStrip
    Private Sub LinesJiwaGridLock(lock As Boolean)
        Dim grid = DirectCast(_purchaseOrderForm.MainUltraTabControl.Tabs("Order").TabPage.Controls.Item("LinesJiwaGrid"), JiwaGrid)
        For Each col As Column In grid.ActiveSheet.Columns
            If Not col.Tag.ToString().StartsWith("UserDefined") Then grid.LockColumn(lock, col.Tag)
        Next
        If _purchaseOrderForm.LinesGridControlContextMenuStrip IsNot Nothing Then _linesGridControlContextMenuStrip = _purchaseOrderForm.LinesGridControlContextMenuStrip
        _purchaseOrderForm.LinesGridControlContextMenuStrip = IIf(lock, Nothing, _linesGridControlContextMenuStrip)
    End Sub

It's not perfect - I get a Object reference not set error on right-click when disabled - but it effectively prevents adding new line items via right-click, which was the intention.

I wasn't able to remove the handler - I can't see that sub from the plugin - I guess it's private (which makes sense).

Cheers,
Neil
neil.interactit
Kohai
Kohai
 
Posts: 232
Joined: Wed Dec 03, 2014 2:36 pm
Topics Solved: 6

Re: Purchase Order - disable right-click insert  Topic is solved

Postby Scott.Pearce » Fri Nov 13, 2015 11:18 am

Damn. The handler is indeed private. But dermis and feline can be divorced by manifold methods...

Add a cellclick handler in the SetupBeforeHandlers, so your routine gets in first. Then, in your routine, hide all the context menu items. I've attached a plugin that does just this.

Exposing the user to a object reference not set error is shameful and you should be ashamed. :-)
Attachments
Plugin Disable Purchase Order Lines Right Click.xml
(33.09 KiB) Downloaded 669 times
Scott Pearce
Senior Analyst/Programmer
Jiwa Financials
User avatar
Scott.Pearce
Senpai
Senpai
 
Posts: 765
Joined: Tue Feb 12, 2008 11:27 am
Location: New South Wales, Australia
Topics Solved: 230


Return to Technical and or Programming

Who is online

Users browsing this forum: No registered users and 2 guests