Results 1 to 9 of 9

Thread: [RESOLVED] Click TreeView Node!

  1. #1

    Thread Starter
    Frenzied Member arpan_de's Avatar
    Join Date
    Oct 2005
    Location
    Mumbai, India
    Posts
    1,394

    Resolved [RESOLVED] Click TreeView Node!

    In a WebBrowser project, a TreeView is used to list the History of the URLs a user has visited. Other than left-clicking any node in the TreeView to navigate to the URLs, users can also navigate by dragging & dropping a node in the WebBrowser. This is how I am implementing it:
    VB Code:
    1. Private Sub TreeView1_MouseDown(Button As Integer, Shift As Integer, x As Single, y As Single)
    2.     If (Button = vbLeftButton) Then
    3.         TreeView1.SelectedItem = TreeView1.HitTest(x, y)
    4.         TreeView1.Drag vbBeginDrag
    5.     End If
    6. End Sub
    7.  
    8. Private Sub wWeb_DragDrop(Source As Control, x As Single, y As Single)
    9.     If Not (Source.SelectedItem Is Nothing) Then
    10.         wWeb.Navigate2 Source.SelectedItem.Tag
    11.     End If
    12. End Sub
    The above code implements the drag-drop feature exactly as I want it but strangely, the WebBrowser doesn't navigate to the Tag of the node (which is the URL) when a node is just left-clicked.

    What am I missing here?


    ARPAN

    IF YOU HAVE AN APPLE & I HAVE AN APPLE AND WE EXCHANGE THE APPLES, THEN YOU & I WILL STILL HAVE ONE APPLE BUT IF YOU HAVE AN IDEA & I HAVE AN IDEA AND WE EXCHANGE OUR IDEAS, THEN EACH OF US WILL HAVE TWO IDEAS!

    NOTHING IS IMPOSSIBLE IN THIS WORLD.....EVEN THE WORD IMPOSSIBLE SAYS I'M POSSIBLE!

    PRACTICE MAKES A MAN PERFECT BUT NOBODY IS PERFECT; SO WHY PRACTICE?

  2. #2
    PowerPoster Static's Avatar
    Join Date
    Oct 2000
    Location
    Rochester, NY
    Posts
    9,390

    Re: Click TreeView Node!

    VB Code:
    1. Private Sub TreeView1_NodeClick(ByVal Node As MSComctlLib.Node)
    2.     wWeb.Navigate2 Node.Tag
    3. End Sub
    JPnyc rocks!! (Just ask him!)
    If u have your answer please go to the thread tools and click "Mark Thread Resolved"

  3. #3
    PowerPoster
    Join Date
    Oct 2002
    Location
    British Columbia
    Posts
    9,758

    Re: Click TreeView Node!

    The Node_Click event occurs after Mouse_Down, however Node_Click will not fire because the Drag operation has taken over. Use the right mouse button for dragging.

  4. #4
    PowerPoster Static's Avatar
    Join Date
    Oct 2000
    Location
    Rochester, NY
    Posts
    9,390

    Re: Click TreeView Node!

    ahh true...

    heres a question... Y "force" (Code) the drag? u can just set the control to allow drag... then u dont have to program it....
    JPnyc rocks!! (Just ask him!)
    If u have your answer please go to the thread tools and click "Mark Thread Resolved"

  5. #5

    Thread Starter
    Frenzied Member arpan_de's Avatar
    Join Date
    Oct 2005
    Location
    Mumbai, India
    Posts
    1,394

    Re: Click TreeView Node!

    heres a question... Y "force" (Code) the drag? u can just set the control to allow drag... then u dont have to program it....
    Sorry, Static, I couldn't exactly follow what are you trying to say. Please clarify!


    ARPAN

    IF YOU HAVE AN APPLE & I HAVE AN APPLE AND WE EXCHANGE THE APPLES, THEN YOU & I WILL STILL HAVE ONE APPLE BUT IF YOU HAVE AN IDEA & I HAVE AN IDEA AND WE EXCHANGE OUR IDEAS, THEN EACH OF US WILL HAVE TWO IDEAS!

    NOTHING IS IMPOSSIBLE IN THIS WORLD.....EVEN THE WORD IMPOSSIBLE SAYS I'M POSSIBLE!

    PRACTICE MAKES A MAN PERFECT BUT NOBODY IS PERFECT; SO WHY PRACTICE?

  6. #6

    Thread Starter
    Frenzied Member arpan_de's Avatar
    Join Date
    Oct 2005
    Location
    Mumbai, India
    Posts
    1,394

    Re: Click TreeView Node!

    Use the right mouse button for dragging.
    Bruce, right-mouse click is already reserved for doing something else.........


    ARPAN

    IF YOU HAVE AN APPLE & I HAVE AN APPLE AND WE EXCHANGE THE APPLES, THEN YOU & I WILL STILL HAVE ONE APPLE BUT IF YOU HAVE AN IDEA & I HAVE AN IDEA AND WE EXCHANGE OUR IDEAS, THEN EACH OF US WILL HAVE TWO IDEAS!

    NOTHING IS IMPOSSIBLE IN THIS WORLD.....EVEN THE WORD IMPOSSIBLE SAYS I'M POSSIBLE!

    PRACTICE MAKES A MAN PERFECT BUT NOBODY IS PERFECT; SO WHY PRACTICE?

  7. #7

    Thread Starter
    Frenzied Member arpan_de's Avatar
    Join Date
    Oct 2005
    Location
    Mumbai, India
    Posts
    1,394

    Re: Click TreeView Node!

    What I don't understand is I am using exactly the same code for a ListView (of course, except for the control names) & it's working perfectly; so what am I missing here?


    ARPAN

    IF YOU HAVE AN APPLE & I HAVE AN APPLE AND WE EXCHANGE THE APPLES, THEN YOU & I WILL STILL HAVE ONE APPLE BUT IF YOU HAVE AN IDEA & I HAVE AN IDEA AND WE EXCHANGE OUR IDEAS, THEN EACH OF US WILL HAVE TWO IDEAS!

    NOTHING IS IMPOSSIBLE IN THIS WORLD.....EVEN THE WORD IMPOSSIBLE SAYS I'M POSSIBLE!

    PRACTICE MAKES A MAN PERFECT BUT NOBODY IS PERFECT; SO WHY PRACTICE?

  8. #8
    PowerPoster
    Join Date
    Oct 2002
    Location
    British Columbia
    Posts
    9,758

    Re: Click TreeView Node!

    Bruce, right-mouse click is already reserved for doing something else.........
    So is the Left-Mouse click, but now you want to use it for two different operations. Plus, for me, the ListView functions exactly the same as the Treeview. This is the code I used

    VB Code:
    1. Private Sub Form_Load()
    2.     With ListView1
    3.         .View = lvwReport
    4.         .ColumnHeaders.Add , , "Testing"
    5.         .ListItems.Add , , "www.windmillsoftware.ca"
    6.         .ListItems.Add , , "www.chinamouldings.com"
    7.         .ListItems(1).Tag = .ListItems(1).Text
    8.         .ListItems(2).Tag = .ListItems(2).Text
    9.         .ColumnHeaders(1).Width = 4000
    10.     End With
    11. End Sub
    12.  
    13. Private Sub ListView1_ItemClick(ByVal Item As MSComctlLib.ListItem)
    14.     Debug.Print "Item Click"
    15. End Sub
    16.  
    17. Private Sub ListView1_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
    18.     If (Button = vbLeftButton) Then
    19.         ListView1.SelectedItem = ListView1.HitTest(X, Y)
    20.         ListView1.Drag vbBeginDrag
    21.     End If
    22. End Sub
    23.  
    24. Private Sub WebBrowser1_DragDrop(Source As Control, X As Single, Y As Single)
    25.     If Not (Source.SelectedItem Is Nothing) Then
    26.         WebBrowser1.Navigate2 Source.SelectedItem.Tag
    27.     End If
    28. End Sub

    Whether it is a TreeView or ListView, the Node_Click and Item_Click events do not fire because of the Drag operation.

  9. #9

    Thread Starter
    Frenzied Member arpan_de's Avatar
    Join Date
    Oct 2005
    Location
    Mumbai, India
    Posts
    1,394

    Re: Click TreeView Node!

    Bruce, I resolved this issue by adding the following code snippet:
    VB Code:
    1. Private Sub TreeView1_DragDrop(Source As Control, x As Single, y As Single)
    2.     wWeb.Navigate2 TreeView1.SelectedItem.Tag
    3. End Sub


    ARPAN

    IF YOU HAVE AN APPLE & I HAVE AN APPLE AND WE EXCHANGE THE APPLES, THEN YOU & I WILL STILL HAVE ONE APPLE BUT IF YOU HAVE AN IDEA & I HAVE AN IDEA AND WE EXCHANGE OUR IDEAS, THEN EACH OF US WILL HAVE TWO IDEAS!

    NOTHING IS IMPOSSIBLE IN THIS WORLD.....EVEN THE WORD IMPOSSIBLE SAYS I'M POSSIBLE!

    PRACTICE MAKES A MAN PERFECT BUT NOBODY IS PERFECT; SO WHY PRACTICE?

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width