PRB: TreeView SelectedItem Property Does Not Return Correct Node (196775)
The information in this article applies to:
- Microsoft Visual Basic Learning Edition for Windows 5.0
- Microsoft Visual Basic Learning Edition for Windows 6.0
- Microsoft Visual Basic Professional Edition for Windows 5.0
- Microsoft Visual Basic Professional Edition for Windows 6.0
- Microsoft Visual Basic Enterprise Edition for Windows 5.0
- Microsoft Visual Basic Enterprise Edition for Windows 6.0
This article was previously published under Q196775 SYMPTOMS
When you try to drag a node from a TreeView control, the SelectedItem property does not point to the correct node.
CAUSE
The SelectedItem property of a TreeView control is not updated until the MouseUp event is fired. This means that in the MouseDown and OLEStartDrag events, the SelectedItem property returns the node that was previously selected.
This behavior is by design so that the user can select a node and then move the mouse off that node if he or she decides not to select that node. The item is not officially selected until the MouseUp event is fired.
RESOLUTION
To work around this behavior, keep track of the currently selected
item manually rather than relying on the SelectedItem property. Use the HitTest method in the MouseDown event to specify this node, as shown in step 9 of the "More Information" section of this article.
Modification Type: | Major | Last Reviewed: | 5/13/2003 |
---|
Keywords: | kbcode kbprb KB196775 |
---|
|