在NodeCheck
事件期间设置checked属性导致它恢复到之前的状态。
例如:检查节点,并触发下面的事件。它发现该节点已被检查并将其设置为false。如果我通过中断遍历代码,节点将在用户界面中反映出这一点。虽然,只要代码点击结束子,复选框就会跳回到设置为真。
Private Sub treeviewExample_NodeCheck(ByVal Node As Object)
If Node.Checked = True Then
Node.Checked = False
ElseIf Node.Checked = False Then
Node.Checked = True
End If
end sub
如何在NodeCheck
事件期间设置checked属性?
我已经尝试了解决方案here,它将节点设置为本地或全局变量,然后设置它,它也会做同样的事情。
答案 0 :(得分:1)
您可以将Checkboxes属性保留为False,并使用Windows API设置复选框属性。然后使用NodeClick事件选择是否选中或取消选中该节点。
Option Explicit
Private Const TVS_CHECKBOXES As Long = &H100
Private Const GWL_STYLE As Long = (-16)
Private Const TVS_HASLINES As Long = 2
Private Const TV_FIRST As Long = &H1100
Private Const TVM_SETBKCOLOR As Long = (TV_FIRST + 29)
Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long
Private Declare Function GetWindowLong Lib "user32" Alias "GetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long) As Long
Private Declare Function SetWindowLong Lib "user32" Alias "SetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long
Private Sub Form_Load()
SetTVCheckboxStyle TreeView1
End Sub
Private Sub SetTVCheckboxStyle(pobjTV As TreeView)
Dim lngCurStyle As Long
Dim lngResult As Long
' === Set the Checkbox style of the TreeView ===
' As advised by Microsoft, due to a bug in the TreeView control,
' set the Checkbox style of the TreeView by using the following
' API calls, rather than simply setting the "Checkboxes" property
' to True ...
lngCurStyle = GetWindowLong(pobjTV.hwnd, GWL_STYLE)
lngResult = SetWindowLong(pobjTV.hwnd, GWL_STYLE, _
lngCurStyle Or TVS_CHECKBOXES)
End Sub
在为节点集添加要禁用的节点的某些属性时,可以稍后检查该属性。我选择使用ForeColor属性,因此禁用的节点将具有禁用的外观。然后使用NodeClick事件来检查,清除或忽略用户点击。
Private Sub TreeView1_NodeClick(ByVal Node As MSComctlLib.Node)
If Node.ForeColor <> vbGrayText Then
Node.Checked = Not Node.Checked
End If
End Sub
答案 1 :(得分:0)
我遇到过这个问题,并发现了一种解决方法。
您无法在自己的NodeCheck事件中设置树视图复选框的'checked-ness'。
但是,假设您正在捕获用户单击复选框,Treeview_Click事件会立即触发(因为他们必须单击以更改它),并且您可以在该事件中设置复选框。< / p>
因此,您需要做的就是存储对需要更改的复选框的引用,并在清除引用之前在Click事件中进行设置。
fireButton.addEventListener("click", function(){
playerGuess = [];
// your other code...
});