Results 1 to 2 of 2
  1. #1
    Miles R is offline Competent Performer
    Windows 10 Office 365
    Join Date
    Mar 2019
    Posts
    280

    Unusual behaviour on Expand and Click events on tree view


    I am getting strange results on my treeview.
    The reason I am having problems is that when I click on the + (expand) of a node, it seems to have the tvwTree.SelectedItem set to the previous item, rather than the item I am expanding.

    On investigation this seems to be due to the events that are triggered.
    When I click the + (expand) button on a node, it seems to either trigger the Expand Event or the Click Event.
    If I put Msgbox "Expand" at the start of the Expand event and Msgbox "Click" at the start of the Click event, then clicking expand causes only the "Expand" message to be shown.
    If I remove the Msgbox "Expand", clicking expand causes the "Click" message to be shown - don't know if the expand event case triggered first though.

    I suspect this is something to do with timing and the Msgbox obviously affects that.

    Can't find out which event should be triggered when pressing + (expand) and why it does not have the correct selected item.

  2. #2
    Miles R is offline Competent Performer
    Windows 10 Office 365
    Join Date
    Mar 2019
    Posts
    280
    After posting this thread I have solved my own problem.
    Firstly, using Msgbox is not a good tool to use for debugging Event issues as it seems to interfere with the triggering of events.
    So, after using more sophisticated debugging methods, I have confirmed that clicking Expand triggers first the Expand Event, then the Click Event - must be documented somewhere but could not find it.

    In the Click Event code, I have code that performs actions based on what I assumed was the Node under the cursor - using tvwTree.SelectedItem.
    This is not always true, as tvwTree.SelectedItem is only changed when actually clicking on the name of an item, not the Expand/Collapse box - in this case, the tvwTree.SelectedItem remains on the last node that was selected.
    So, to solve my problem, I save the last node actually selected (highlighted in Blue) and only take action in the Click Event code if the tvwTree.SelectedItem has changed.

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 3
    Last Post: 12-20-2017, 01:00 AM
  2. Access expand node of tree in datasheetview
    By jaryszek in forum Programming
    Replies: 8
    Last Post: 07-25-2017, 06:32 AM
  3. Tree View structure for BOM
    By arunhalyal in forum Access
    Replies: 1
    Last Post: 10-06-2013, 09:49 PM
  4. Replies: 3
    Last Post: 03-08-2013, 06:32 PM
  5. Percent textbox unusual behaviour
    By Deutz in forum Forms
    Replies: 4
    Last Post: 06-05-2011, 06:46 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums