|
-
Mar 10th, 2006, 01:16 AM
#1
Thread Starter
Member
[RESOLVED] Treeview problem Urgent!!
VB Code:
Dim strKEy As String
Dim RemoteHost As String
Private Sub Form_Load()
Dim x
Dim PCName As String
Dim Command As String
Dim Msg As String
Dim i As Integer
' Declarations
Dim intIDX As Integer
' Get List of Computers on Network (Type All: Server and Workstation)
ServerList = EnumServer(SRV_TYPE_ALL)
' Loop through all the computers and add them to the treeview
If ServerList.Init Then
Dim rt As Node
Dim ch As Node
Dim strServer As String
Dim t
Set rt = TreeView1.Nodes.Add(, , "rootnode", "Sistem Kawalan Makmal")
For intIDX = 1 To UBound(ServerList.List)
strServer = ServerList.List(intIDX).ServerName
t = strServer & intIDX
Set ch = TreeView1.Nodes.Add(rt, tvwChild, t, strServer)
rt.Expanded = True
Next
End If
TreeView1.Nodes(1).Selected = True
strKEy = TreeView1.SelectedItem.Key
End Sub
Private Sub TreeView1_MouseDown(Button As Integer, Shift As Integer, x As Single, y As Single)
Dim str
If strKEy <> "" Then
If TreeView1.Nodes(strKEy).Parent Is Nothing Then
If Button = 2 Then ' if the mousebutton 2 is pressed (right)
PopupMenu Rclick ' then it calls the menu which is hidden to be shown at the cordinates of the mousepointer (x,y)
Else
Button = 1
RemoteHost = TreeView1.Nodes(strKEy).Text
sckControlPanel.RemoteHost = RemoteHost
sckControlPanel.RemotePort = 8005
sckControlPanel.Connect
MsgBox (" " & TreeView1.Nodes(strKEy).Text)
End If
End If
Else
sckControlPanel.Close
Call sckControlPanel_Close
End If
Data1.Refresh
End Sub
Hai you guys, the above are the code to generate connected computer on the same network and displaying it in treeview. The problem here is the left click can't seem to function. I have tried putting a MsgBox at the button 1 to see what is it displaying when i click on the node and no matter what i click it will only display the root node name. This mean that i can't select the other computer name so it can't connect to the other computer.
RemoteHost = TreeView1.Nodes(strKEy).Text
Is there something wrong with this line. Can someone tell me what is wrong? Thanks in advanced
-
Mar 10th, 2006, 01:25 AM
#2
Frenzied Member
Re: Treeview problem Urgent!!
try to remove the Button = 1
just a wild gues
whats EnumServer?
Last edited by d3gerald; Mar 10th, 2006 at 01:29 AM.
On error goto Trap
Trap:
in case of emergency, drop the case...
****************************************
If this post has been resolved. Please mark it as "Resolved" by going through the "Thread Tools" above and clicking on the "Mark Thread Resolved " option. if a post is helpful to you, Please Rate it by clicking on the Rate link right below the avatar
-
Mar 10th, 2006, 02:12 AM
#3
Thread Starter
Member
Re: Treeview problem Urgent!!
No that doesn't work i just tried it. Thanks anyway
-
Mar 10th, 2006, 02:38 AM
#4
Re: Treeview problem Urgent!!
The value of the variable strKey is set in the Form_Load event but is never changed, so the code
TreeView1.Nodes(strKEy).Text
will always point to the same Node.
Plus, based on the code, you only have one Root node which means all other nodes have a Parent. The If Node.Parent Is Nothing will only be True for this Root node
Last edited by brucevde; Mar 10th, 2006 at 02:47 AM.
-
Mar 10th, 2006, 09:53 AM
#5
Thread Starter
Member
What do i have to change??
Please tell me what do i have to change? I have been stuck with this for 1 week and no one know what is wrong with it? Please help me...
Thanks
-
Mar 10th, 2006, 11:21 AM
#6
Thread Starter
Member
Re: Treeview problem Urgent!!
Can anyone help me with this???
-
Mar 10th, 2006, 11:53 AM
#7
Hyperactive Member
Re: Treeview problem Urgent!!
strKEy = TreeView1.SelectedItem.Key
try
strKEy = TreeView1.SelectedItem.index
-
Mar 11th, 2006, 01:46 AM
#8
Thread Starter
Member
Re: Treeview problem Urgent!!
VB Code:
Private Sub TreeView1_MouseDown(Button As Integer, Shift As Integer, x As Single, y As Single)
If strKEy <> "" Then
'If TreeView1.Nodes(strKEy).Parent Is Nothing Then
If Button = 2 Then ' if the mousebutton 2 is pressed (right)
PopupMenu Rclick ' then it calls the menu which is hidden to be shown at the cordinates of the mousepointer (x,y)
Else
Button = 1
RemoteHost = TreeView1.SelectedItem 'TreeView1.Nodes(strKEy).Text
sckControlPanel.RemoteHost = RemoteHost
sckControlPanel.RemotePort = 8005
sckControlPanel.Connect
'MsgBox (" " & TreeView1.SelectedItem)
End If
'End If
Else
sckControlPanel.Close
Call sckControlPanel_Close
End If
Data1.Refresh
End Sub
I have tried with this MsgBox (" " & TreeView1.SelectedItem) and it can display the correct node name. But the the mouse click always go to the root node and not the node which i want to click, i have to use the down button then only i can click on the other node. Why is this so? I tried with
Button = 1
RemoteHost = TreeView1.SelectedItem
sckControlPanel.RemoteHost = RemoteHost
sckControlPanel.RemotePort = 8005
sckControlPanel.Connect
But due to the problem above it can't work. I have tried to just set the remote host to the client IP and it can connect fine. Can someone help me with this...??
Thanks in advance
-
Mar 11th, 2006, 11:15 AM
#9
Re: Treeview problem Urgent!!
The strKey portion is still unclear to me so I ignored it. The following might give you some new ideas. Handle the Right Mouse click in MouseDown but use the NodeClick event when setting the sckControlPanel properties. NodeClick is like a "GotFocus" event for each Node.
VB Code:
Private Sub TreeView1_MouseDown(Button As Integer, Shift As Integer, x As Single, y As Single)
Dim oNode As Node
If Button = vbRightButton Then
'make sure the user clicked on a node
Set oNode = TreeView1.HitTest(x, y)
If Not oNode Is Nothing Then
PopupMenu mnuPopup, , x, y
End If
End If
End Sub
Private Sub TreeView1_NodeClick(ByVal Node As MSComctlLib.Node)
RemoteHost = Node.Text
sckControlPanel.RemoteHost = RemoteHost
sckControlPanel.RemotePort = 8005
sckControlPanel.Connect
End Sub
-
Mar 11th, 2006, 11:59 AM
#10
Thread Starter
Member
[Solved]Re: Treeview problem Urgent!!
Thank alot brucevde
You are the best. I have asked in many forums but no one knew what is the problem or how to solve it. But with the coding you gave solve my problem. Thanks alot. After stuck in this part for so long now i can move on to the next part which is the colour of the nodes.
Thanks you so very much you are the best.
Thanks to all you guys who try to help me too. Thanks alot....
-
Mar 11th, 2006, 12:36 PM
#11
Thread Starter
Member
Re: Treeview problem Urgent!!
To brucevde
Private Sub TreeView1_MouseDown(Button As Integer, Shift As Integer, x As Single, y As Single)
Dim oNode As Node
If Button = 2 Then 'vbRightButton
'make sure the user clicked on a node
'Set oNode = TreeView1.HitTest(x, y)
'If Not oNode Is Nothing Then
PopupMenu Rclick ', , x, y
'End If
End If
End Sub
I have close these lines
'Set oNode = TreeView1.HitTest(x, y)
'If Not oNode Is Nothing Then
PopupMenu Rclick ', , x, y
'End If
Except for the PopupMenu Rclick because when i use it the pop up menu pop up at the top of the form and not at the tip of the mouse cursor. What is the above line for? Can you tell it to me. Thanks alot
-
Mar 11th, 2006, 03:52 PM
#12
Re: Treeview problem Urgent!!
Set oNode = TreeView1.HitTest(x, y)
If Not oNode Is Nothing Then
The first line checks to see if a Node is located at the Mouse coordinates (x,y). IE Did the user Right Click on a Node? If Yes, the oNode variable will reference a Node in the TreeView. If No, the oNode variable will be Nothing.
Basically, the popup menu is only shown if the user Right Clicks on the text of a Node. If that is not a requirement for you then obviously comment out (or delete)those lines as you already have done.
-
Mar 11th, 2006, 04:47 PM
#13
Re: Treeview problem Urgent!!
that was smart coding bruce!! .by the way one thing how can one change the color of a particular node in a similar way .
Last edited by litlewiki; Mar 12th, 2006 at 01:38 AM.
-
Mar 12th, 2006, 02:17 AM
#14
Thread Starter
Member
Re: Treeview problem Urgent!!
Thanks for your explaination Bruce. I also use the right click function but i have make a bit change to it
VB Code:
Private Sub TreeView1_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
Dim oNode As Node
If Button = vbRightButton Then
'make sure the user clicked on a node
Set oNode = TreeView1.HitTest(X, Y)
If Not oNode Is Nothing Then
PopupMenu Rclick
Else
sckControlPanel.Close
Call sckControlPanel_Close
End If
End If
End Sub
You see the originally coding
PopupMenu Rclick, , x, y
With the ", , x, y" behind PopupMenu Rclick will make the popup run to the top of the form. So i have taken it out and the popup will popup at the tip of the mouse cursor. Now my next step is to make the nodes to dispaly in different colour. Thanks alot
-
Mar 12th, 2006, 02:42 AM
#15
Re: Treeview problem Urgent!!
Now my next step is to make the nodes to dispaly in different colour.
That is easy, each Node has ForeColor and BackColor properties. Unfortunately, the Treeview itself does not have a Backcolor property, so setting the BackColor property of each Node is just ugly. But ForeColor is alright, here is a quick example.
VB Code:
Private Sub Form_Load()
Dim lngIdx As Long
Dim oNode As Node
With Me.TreeView1
.LineStyle = tvwRootLines
For lngIdx = 1 To 3
Set oNode = .Nodes.Add(, , , "Root " & lngIdx)
oNode.ForeColor = vbRed
oNode.Expanded = True
Next
For lngIdx = 1 To 3
'VB Color constants
Set oNode = .Nodes.Add(lngIdx, tvwChild, , "Parent " & lngIdx)
oNode.ForeColor = vbBlue
'or use the RGB function
Set oNode = .Nodes.Add(lngIdx, tvwChild, , "Parent " & lngIdx)
oNode.ForeColor = RGB(0, 0, 172)
Next
End With
End Sub
-
Mar 12th, 2006, 09:49 AM
#16
Thread Starter
Member
Re: Treeview problem Urgent!!
Thanks alot for your coding Bruce. I just use like this to display the Parent and the children nodes colour
'To display computer in TreeView
Set rt = TreeView1.Nodes.Add(, , "Root Node", "Lab Control")
rt.ForeColor = vbBlue ' Set the colour of Root to blue
For intIDX = 1 To UBound(ServerList.List)
strServer = ServerList.List(intIDX).ServerName
t = strServer & intIDX
Set ch = TreeView1.Nodes.Add(rt, tvwChild, t, strServer)
ch.ForeColor = vbGreen
rt.Expanded = True
Next
End If
I have set all to green 1st then when i lock the computers it should be green then when the computer is in use the node forecolor will be set to vbRed. If i is shutdown then then forecolor will be set to vbBlack.
Take care and have a nice day.... Thanks again
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|