Page 1 of 1

Purchase Order - disable right-click insert

PostPosted: Wed Nov 04, 2015 2:30 pm
by neil.interactit
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 5257 times

I can't quite see how to do this?

Cheers,
Neil

Re: Purchase Order - disable right-click insert

PostPosted: Wed Nov 04, 2015 3:27 pm
by Scott.Pearce
See if the grid has a ContextMenuStrip property. If it does, set it to Nothing. This *may* work. Let me know.

Re: Purchase Order - disable right-click insert

PostPosted: Wed Nov 04, 2015 4:39 pm
by neil.interactit
No go. I tried both:
Code: Select all
        grid.ContextMenuStrip = Nothing
        grid.ContextMenu = Nothing

The right-click still works.

Re: Purchase Order - disable right-click insert

PostPosted: Wed Nov 04, 2015 4:41 pm
by Scott.Pearce
Dang. We must use a special context menu control separate from the grid. Standby, I'll go find it.

Re: Purchase Order - disable right-click insert

PostPosted: Wed Nov 04, 2015 4:48 pm
by Scott.Pearce
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.

Re: Purchase Order - disable right-click insert

PostPosted: Tue Nov 10, 2015 4:15 pm
by neil.interactit
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

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

PostPosted: Fri Nov 13, 2015 11:18 am
by Scott.Pearce
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. :-)