ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Problems with preventing the user of setting a checkbox of a treeview (https://www.excelbanter.com/excel-programming/299206-problems-preventing-user-setting-checkbox-treeview.html)

Jurry[_13_]

Problems with preventing the user of setting a checkbox of a treeview
 
I want to prevent that users select certain checkboxes of a treeview.
tried doing that by placing a routine in the NodeCheck event of th
treeview. During debuging I see the checkbox being set back to my ow
value, but after the whole event the checkbox has the users value! S
in short the following code does not work, why not?

Private Sub treeSpotsOverview_NodeCheck(ByVal Node As MSComctlLib.Node

tree.Nodes(Node.index).Checked = True
End Sub

Thanks, Jurry.
PS: I'm using VBA

--
Message posted from http://www.ExcelForum.com


Jurry[_15_]

Problems with preventing the user of setting a checkbox of a treeview
 
After searching on the net I found the following workaround for this BU
in VB: you have the use the event MouseUp. This event takes alway
place after the clicking of a node by the user (and therefore AFTER th
NodeCheck event). In combination with a global var the result is:

In a standard module:

Code
-------------------
Public gnodNodeWithCheckboxToBeProcessed As MSComctlLib.Nod
-------------------

In the treeview dialog module:

Code
-------------------
Private Sub treeSpotsOverview_MouseUp(ByVal Button As Integer, ByVal Shift As Integer, ByVal x As stdole.OLE_XPOS_PIXELS, ByVal y As stdole.OLE_YPOS_PIXELS)
' used to work around the bug in VB to alter the checkbox state during the
' nodecheck event
If Not gnodNodeWithCheckboxToBeProcessed Is Nothing Then
gupvlPlateValues.HandleTreeCheckboxChange gnodNodeWithCheckboxToBeProcessed
Set gnodNodeWithCheckboxToBeProcessed = Nothing
End If
End Sub

Private Sub treeSpotsOverview_NodeCheck(ByVal Node As MSComctlLib.Node)
' Actual action in the mouseup event due to bug of VB
Set gnodNodeWithCheckboxToBeProcessed = treeSpotsOverview.Nodes(Node.Index)
End Su
-------------------


Have fun with it,
Jurry

--
Message posted from http://www.ExcelForum.com



All times are GMT +1. The time now is 01:34 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com