BUG:TreeView: NodeCheck Event Does Not Occur
2009-12-28 09:30
537 查看
BUG: TreeView: NodeCheck Event Does Not Occur
View products that this article applies to.if (!loadTOCNode) {var loadTOCNode = function(){}}This article was previously published under Q221557
On This Page
![](http://support.microsoft.com/library/images/support/kbgraphics/public/en-us/downarrow.gif)
SYMPTOMS
![](http://support.microsoft.com/library/images/support/kbgraphics/public/en-us/downarrow.gif)
RESOLUTION
![](http://support.microsoft.com/library/images/support/kbgraphics/public/en-us/downarrow.gif)
Step by Step Example
![](http://support.microsoft.com/library/images/support/kbgraphics/public/en-us/downarrow.gif)
STATUS
![](http://support.microsoft.com/library/images/support/kbgraphics/public/en-us/downarrow.gif)
MORE INFORMATION
![](http://support.microsoft.com/library/images/support/kbgraphics/public/en-us/downarrow.gif)
Steps to Reproduce Behavior
![](http://support.microsoft.com/library/images/support/kbgraphics/public/en-us/downarrow.gif)
REFERENCES
var sectionFilter = "type != 'notice' && type != 'securedata' && type != 'querywords'";
var tocArrow = "/library/images/support/kbgraphics/public/en-us/downarrow.gif";
var depthLimit = 10;
var depth3Limit = 10;
var depth4Limit = 5;
var depth5Limit = 3;
var tocEntryMinimum = 1;
#tocTitle, #tocDiv{display: none;}
Expand all | Collapse all
if (kb_page_object)
{
kb_page_object.kb_imageExpandHoverText = 'Click to expand this image';
}
SYMPTOMS
When a TreeView control with the Checkboxes property set to True is placed on a...
loadTOCNode(1, 'symptoms');When a TreeView control with the Checkboxes property set to True is placed on a form and the user presses the left-mouse button over a checkbox and then drags the mouse away from the checkbox before releasing the mouse button, the state of the checkbox is toggled, but a NodeCheck event does not occur.
![](http://support.microsoft.com/library/images/support/kbgraphics/public/en-us/uparrow.gif)
Back to the top
RESOLUTION
You can work around the problem by programmatically ensuring that the event occu...
loadTOCNode(1, 'resolution');You can work around the problem by programmatically ensuring that the event occurs if the mouse has been dragged away from the checkbox.
![](http://support.microsoft.com/library/images/support/kbgraphics/public/en-us/uparrow.gif)
Back to the top
Step by Step Example
loadTOCNode(2, 'resolution');Open a new Visual Basic Standard Exe project. Form1 is created by default.
On the Project menu, click Components. Select Microsoft Common Controls 6.0 and click OK.
Add a TreeView control to Form1.
Add the following code to the General Declarations section of Form1:
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 ' <--- ' treeview messages Private Const TV_FIRST = &H1100 ' wParam = 0, lParam = lptvhti, rtns hItem Private Const TVM_HITTEST = (TV_FIRST + 17) Private Type POINTAPI ' pt x As Long y As Long End Type ' structure passed with the TVM_HITTEST message Private Type TVHITTESTINFO pt As POINTAPI flags As Long hItem As Long End Type ' TVHITTESTINFO.flags value. An item's checkbox ' is in fact held in the item's state icon image. Private Const TVHT_ONITEMSTATEICON = &H40 Private m_nodChecked As Node Private Sub Form_Load() Dim Node1 As Node Dim Node2 As Node Dim Node3 As Node Dim i As Integer Dim j As Integer Dim k As Integer ' For some convenience... With TreeView1 .HideSelection = False .Indentation = 19 * Screen.TwipsPerPixelX .LabelEdit = tvwManual .LineStyle = tvwRootLines .Checkboxes = True End With ' Fill up the treeview... For i = 1 To 2 Set Node1 = TreeView1.Nodes.Add(, , , "Root" & i) For j = 1 To 3 Set Node2 = TreeView1.Nodes.Add(Node1.Index, tvwChild, , _ "Root" & i & "Child" & j) For k = 1 To 3 Set Node3 = TreeView1.Nodes.Add(Node2.Index, tvwChild, , _ "GrandChild" & (16 * (i - 1)) + (4 * (j - 1)) + k) Next k Next j Node1.Expanded = True Next i End Sub Private Sub TreeView1_MouseDown(Button As Integer, Shift As Integer, _ x As Single, y As Single) Dim tvhti As TVHITTESTINFO Debug.Print "MouseDown: " & Button & " " & Shift & " " & _ x & " " & y If (Button = vbLeftButton) Then ' determine if the mouse pointer is being depressed over the Node's ' checkbox (assumes that the Form's ScaleMode is set to vbTwips). tvhti.pt.x = x / Screen.TwipsPerPixelX tvhti.pt.y = y / Screen.TwipsPerPixelY If (SendMessage(TreeView1.hWnd, TVM_HITTEST, 0, tvhti)) Then If (tvhti.flags And TVHT_ONITEMSTATEICON) Then ' the value of the Node's Checked property will be toggled ' *after* this procedure finishes execution. Set m_nodChecked = TreeView1.HitTest(x, y) End If End If ' TVM_HITTEST End If ' (Button = vbLeftButton) End Sub Private Sub TreeView1_NodeCheck(ByVal Node As MSComctlLib.Node) If (Node Is m_nodChecked) Then ' Either the left-mouse button is being released over the Node ' whose checkbox has been toggled, or this event procedure ' is being called from TreeView1_MouseUp. This *is* where we ' want to process code... Debug.Print "NodeCheck: " & m_nodChecked & _ ".Checked = " & m_nodChecked.Checked & _ vbCrLf & vbTab & " (do process code here)" ' De-reference the module level Node variable so you don't ' call this event again in TreeView1_MouseUp. Set m_nodChecked = Nothing Else ' This event is being raised by the TreeView because the mouse ' pointer is being released over a node whose checkbox state ' has *not* been toggled. you do *not* want to process code here... Debug.Print "NodeCheck: " & Node & _ ".Checked = " & Node.Checked & _ vbCrLf & vbTab & " (do *not* process code here)" End If End Sub Private Sub TreeView1_MouseUp(Button As Integer, Shift As Integer, _ x As Single, y As Single) If (m_nodChecked Is Nothing) = False Then ' You didn't get a NodeCheck event (the variable is still set), ' the mouse pointer is *not* over the Node whose checkbox ' state has been toggled. Explicitly call the event procedure. Call TreeView1_NodeCheck(m_nodChecked) End If Debug.Print "MouseUp: " & Button & " " & Shift & " " & _ x & " " & y End Sub
Run the program and position the mouse cursor over a checkbox. Press and hold down the left-mouse button, drag the mouse cursor away from the checkbox, and then release the mouse button. Note that a message verifying that the NodeCheck event occurred is printed in the Immediate pane.
![](http://support.microsoft.com/library/images/support/kbgraphics/public/en-us/uparrow.gif)
Back to the top
STATUS
Microsoft has confirmed that this is a bug in the Microsoft products that are li...
loadTOCNode(1, 'status');Microsoft has confirmed that this is a bug in the Microsoft products that are listed at the beginning of this article.
![](http://support.microsoft.com/library/images/support/kbgraphics/public/en-us/uparrow.gif)
Back to the top
MORE INFORMATION
Steps to Reproduce Behavior Open a new Visual Basic Standard Exe project. Form1...
loadTOCNode(1, 'moreinformation');Steps to Reproduce Behavior
loadTOCNode(2, 'moreinformation');Open a new Visual Basic Standard Exe project. Form1 is created by default.
On the Project menu, click Components. Select Microsoft Common Controls 6.0 and click OK.
Add a Treeview control to Form1. Open the Treeview control's property page by right-clicking on the control and clicking Properties. Check the Treeview control's Checkboxes property and click OK.
Add the following code to the General Declarations section of Form1:
Private Sub Form_Load() Dim Node1 As Node Dim Node2 As Node Dim Node3 As Node Dim i As Integer Dim j As Integer Dim k As Integer ' For some convenience... With TreeView1 .HideSelection = False .Indentation = 19 * Screen.TwipsPerPixelX .LabelEdit = tvwManual .LineStyle = tvwRootLines End With ' Fill up the treeview... For i = 1 To 2 Set Node1 = TreeView1.Nodes.Add(, , , "Root" & i) For j = 1 To 3 Set Node2 = TreeView1.Nodes.Add(Node1.Index, tvwChild, , _ "Root" & i & "Child" & j) For k = 1 To 3 Set Node3 = TreeView1.Nodes.Add(Node2.Index, tvwChild, , _ "GrandChild" & (16 * (i - 1)) + (4 * (j - 1)) + k) Next k Next j Node1.Expanded = True Next i End Sub Private Sub TreeView1_NodeCheck(ByVal Node As MSComctlLib.Node) Debug.Print "NodeCheck Event" End Sub
Run the program. Position the mouse cursor over a checkbox, press and release the left-mouse button on the checkbox, and note that the message is printed in the Immediate pane.
Position the mouse cursor over a checkbox, and press and hold down the left-mouse button. Drag the mouse cursor away from the checkbox and then release the mouse button. Note that no message appears.
![](http://support.microsoft.com/library/images/support/kbgraphics/public/en-us/uparrow.gif)
Back to the top
http://support.microsoft.com/kb/221557/en-us/
相关文章推荐
- Treeview SelectedNodeChanged event not firing
- 解決 yum update錯誤:[Errno -1] Metadata file does not match checksum
- VS2008 TreeView控件的TreeNodeCheckChanged事件自动回发到服务器端
- Explain tables does not exist. Check the explain plan properties for this database connection.
- TreeView.AfterCheck和TreeNode.Checked赋值的问题
- [ERR] Node 172.168.63.202:7001 is not empty. Either the nodealready knows other nodes (check with CL
- 【bug】org.hibernate.dialect.OracleDialect does not support identity key generation
- 如何让TreeView的TreeNodeCheckChanged事件自动回发到服务器端
- Node的事件驱动艺术bug实例(bugs in server-side event driven architecture (EDA))
- 解決yum [Errno -1] Metadata file does not match checksum
- 解決yum [Errno -1] Metadata file does not match checksum
- 微软VC各版本BUG: error C2660: 'new' : function does not take 3 parameters
- PRVG-11074 : Private network interface "name" on node "node" does not have MONITOR option set
- [ERR] Node 192.168.25.128:7111 is not empty. Either the node already knows other nodes (check with C
- ie does not support the event of the option in select control
- bug:The application bundle does not contain a valid identifier
- bug:TClientDataSet does not stream out "empty" TWideStringField values properly
- spring整合mybatis bug解决java.lang.IllegalArgumentException: Mapped Statements collection does not contain value for ...
- 如何响应TreeView中的OnTreeNodeCheckChanged事件
- 如何让TreeView的TreeNodeCheckChanged事件自动回发到服务器端