I'm using the good ol treeview and I can get everything else to seem to work with it except i want to make 1 of the nodes a weblink so when it's clicked it just opens up the page.
I have the code attached to a label right now and it works great... it opens up the default browser and goes right to that page w/ no problem, I only have the problem when I attach it to the node from treeview. Here is what i'm working with...
Code:
Private Sub TreeView1_NodeClick(ByVal Node As MSComctlLib.Node)
If Node = "gohome" Then
FilePath = "hxxp://xxx.site.com"
OpenFileDefault hwnd, "open", FilePath, vbNullString, _
vbNullString, 1
End If
End Sub
Wasn't quite sure how I would go about fixing this problem. Didn't know if it was b/c of having "MSComctlLib" in that code or not.
Private Declare Function ShellExecute Lib "shell32.dll" Alias "ShellExecuteA" (ByVal hwnd As Long, ByVal lpOperation _
As String, ByVal lpFile As String, ByVal lpParameters As String, ByVal lpDirectory As String, ByVal nShowCmd As Long) As Long
Then, on node click event:
Code:
Private Sub TreeView1_NodeClick(ByVal Node As MSComctlLib.Node)
dim ret&
If Node = "gohome" Then
FilePath = "hxxp://xxx.site.com"
ret = ShellExecute(Me.hwnd, "OPen", FilePath, "", "", 1)
End If
End Sub
No Sorry... It didn't help any. I already had this code entered
Code:
Private Declare Function OpenFileDefault Lib _
"shell32.dll" Alias "ShellExecuteA" (ByVal hwnd As Long, _
ByVal lpOperation As String, ByVal lpFile As String, _
ByVal lpParameters As String, ByVal lpDirectory As String, _
ByVal nShowCmd As Long) As Long
which is pretty much the same thing. I did try it though. Tried to swap out my old code for yours.
Private Declare Function ShellExecute Lib "shell32.dll" Alias "ShellExecuteA" (ByVal hwnd As Long, ByVal lpOperation _
As String, ByVal lpFile As String, ByVal lpParameters As String, ByVal lpDirectory As String, ByVal nShowCmd As Long) As Long
Private Sub TreeView1_Click()
Dim ret&
Dim filepath
filepath = "http://www.google.com"
ret = ShellExecute(Me.hwnd, "OPen", filepath, "", "", 1)
End Sub
It must work with yours. Try making Breakpoints to see where it seek those instructions.
Thanx... it worked. Still don't know what the problem was about the code but its all good now.
Also I was wondering what kinda code would be involved in making it so when i opened my program the whole treeview would be collapsed? Since everytime i open it they are all opened as far as they can go...
Tried searching but didn't find the code/help i needed
To Collapse use .Expanded = False, to Expand .Expanded = True.
You can use a recursive Call like this to Expand/Collapse all nodes:
Code:
Private Sub ExpandTree(ByVal pNode As MSComctlLib.Node, pCollapse As Boolean)
Dim oChildNode As Node
pNode.Expanded = pCollapse
Set oChildNode = pNode.Child
Do Until oChildNode Is Nothing
oChildNode.Expanded = pCollapse
ExpandTree oChildNode, pCollapse 'Recursive Call
Set oChildNode = oChildNode.Next
Loop
End Sub
Couldn't get either of your code to work right ...
jcis I had the best luck w/ your code but i couldn't get it to collapse more than the 1st child. This is kinda how it looks now...
- Main1
| - Second
| Third
| - Second
| Third
-Main2
| -Second
| Third
| -Second
and so on...
I wanted to make it collapse on Form_Load to look like this
+Main1
+Main2
+Main3
etc...
I will try to work w/ the code provided since y'all were nice enough to help out.
Maybe i'm just not seeing what I should be, I have been staring at this code for prolly a couple of hours. And I should take a break.
Private Sub ExpandTree(pCollapse As Boolean)
Dim lNode As Node
For Each lNode In TreeView1.Nodes
lNode.Expanded = pCollapse
Next
Set lNode = Nothing
End Sub