Results 1 to 16 of 16

Thread: [RESOLVED] Treeview problem Urgent!!

  1. #1

    Thread Starter
    Member
    Join Date
    Feb 2006
    Posts
    61

    Resolved [RESOLVED] Treeview problem Urgent!!

    VB Code:
    1. Dim strKEy As String
    2. Dim RemoteHost As String
    3.  
    4.  Private Sub Form_Load()
    5.     Dim x
    6.     Dim PCName As String
    7.     Dim Command As String
    8.     Dim Msg As String
    9.     Dim i As Integer
    10.  
    11.  ' Declarations
    12.     Dim intIDX As Integer
    13.    
    14.     ' Get List of Computers on Network (Type All: Server and Workstation)
    15.     ServerList = EnumServer(SRV_TYPE_ALL)
    16.    
    17.      ' Loop through all the computers and add them to the treeview
    18.     If ServerList.Init Then
    19.    
    20.         Dim rt As Node
    21.         Dim ch As Node
    22.         Dim strServer As String
    23.         Dim t
    24.         Set rt = TreeView1.Nodes.Add(, , "rootnode", "Sistem Kawalan Makmal")
    25.      
    26.         For intIDX = 1 To UBound(ServerList.List)
    27.             strServer = ServerList.List(intIDX).ServerName
    28.             t = strServer & intIDX
    29.             Set ch = TreeView1.Nodes.Add(rt, tvwChild, t, strServer)
    30.             rt.Expanded = True
    31.          
    32.         Next
    33.            
    34.     End If
    35.  
    36.  TreeView1.Nodes(1).Selected = True
    37.    strKEy = TreeView1.SelectedItem.Key
    38. End Sub
    39.  
    40. Private Sub TreeView1_MouseDown(Button As Integer, Shift As Integer, x As Single, y As Single)
    41. Dim str
    42.  
    43. If strKEy <> "" Then
    44.     If TreeView1.Nodes(strKEy).Parent Is Nothing Then
    45.  
    46.         If Button = 2 Then ' if the mousebutton 2 is pressed (right)
    47.             PopupMenu Rclick ' then it calls the menu which is hidden to be shown at the cordinates of the mousepointer (x,y)
    48.  
    49.         Else
    50.  
    51.             Button = 1
    52.             RemoteHost = TreeView1.Nodes(strKEy).Text
    53.             sckControlPanel.RemoteHost = RemoteHost
    54.             sckControlPanel.RemotePort = 8005
    55.             sckControlPanel.Connect
    56.             MsgBox (" " & TreeView1.Nodes(strKEy).Text)
    57.         End If
    58.     End If
    59. Else
    60.  
    61. sckControlPanel.Close
    62. Call sckControlPanel_Close
    63.  
    64. End If
    65.  
    66. Data1.Refresh
    67. 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

  2. #2
    Frenzied Member d3gerald's Avatar
    Join Date
    Jan 2006
    Posts
    1,348

    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

  3. #3

    Thread Starter
    Member
    Join Date
    Feb 2006
    Posts
    61

    Re: Treeview problem Urgent!!

    No that doesn't work i just tried it. Thanks anyway

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

    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.

  5. #5

    Thread Starter
    Member
    Join Date
    Feb 2006
    Posts
    61

    Exclamation 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

  6. #6

    Thread Starter
    Member
    Join Date
    Feb 2006
    Posts
    61

    Unhappy Re: Treeview problem Urgent!!

    Can anyone help me with this???

  7. #7
    Hyperactive Member
    Join Date
    Feb 2006
    Location
    Philippines
    Posts
    468

    Re: Treeview problem Urgent!!

    strKEy = TreeView1.SelectedItem.Key
    try
    strKEy = TreeView1.SelectedItem.index

  8. #8

    Thread Starter
    Member
    Join Date
    Feb 2006
    Posts
    61

    Exclamation Re: Treeview problem Urgent!!

    VB Code:
    1. Private Sub TreeView1_MouseDown(Button As Integer, Shift As Integer, x As Single, y As Single)
    2. If strKEy <> "" Then
    3.     'If TreeView1.Nodes(strKEy).Parent Is Nothing Then
    4.  
    5.         If Button = 2 Then ' if the mousebutton 2 is pressed (right)
    6.             PopupMenu Rclick ' then it calls the menu which is hidden to be shown at the cordinates of the mousepointer (x,y)
    7.  
    8.         Else
    9.  
    10.             Button = 1
    11.             RemoteHost = TreeView1.SelectedItem 'TreeView1.Nodes(strKEy).Text
    12.             sckControlPanel.RemoteHost = RemoteHost
    13.             sckControlPanel.RemotePort = 8005
    14.             sckControlPanel.Connect
    15.           'MsgBox (" " & TreeView1.SelectedItem)
    16.         End If
    17.     'End If
    18. Else
    19.  
    20. sckControlPanel.Close
    21. Call sckControlPanel_Close
    22.  
    23. End If
    24.  
    25. Data1.Refresh
    26. 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

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

    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:
    1. Private Sub TreeView1_MouseDown(Button As Integer, Shift As Integer, x As Single, y As Single)
    2.     Dim oNode As Node
    3.     If Button = vbRightButton Then
    4.         'make sure the user clicked on a node
    5.         Set oNode = TreeView1.HitTest(x, y)
    6.         If Not oNode Is Nothing Then
    7.             PopupMenu mnuPopup, , x, y
    8.         End If
    9.     End If
    10. End Sub
    11.  
    12. Private Sub TreeView1_NodeClick(ByVal Node As MSComctlLib.Node)
    13.     RemoteHost = Node.Text
    14.     sckControlPanel.RemoteHost = RemoteHost
    15.     sckControlPanel.RemotePort = 8005
    16.     sckControlPanel.Connect
    17. End Sub

  10. #10

    Thread Starter
    Member
    Join Date
    Feb 2006
    Posts
    61

    Thumbs up [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....

  11. #11

    Thread Starter
    Member
    Join Date
    Feb 2006
    Posts
    61

    Talking 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

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

    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.

  13. #13
    Frenzied Member litlewiki's Avatar
    Join Date
    Dec 2005
    Location
    Zeta Reticuli Distro:Ubuntu Fiesty
    Posts
    1,162

    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.

  14. #14

    Thread Starter
    Member
    Join Date
    Feb 2006
    Posts
    61

    Red face 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:
    1. Private Sub TreeView1_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
    2.     Dim oNode As Node
    3.     If Button = vbRightButton Then
    4.         'make sure the user clicked on a node
    5.         Set oNode = TreeView1.HitTest(X, Y)
    6.         If Not oNode Is Nothing Then
    7.             PopupMenu Rclick
    8.            
    9.    Else
    10.       sckControlPanel.Close
    11.     Call sckControlPanel_Close
    12.    
    13.         End If
    14.        
    15.     End If
    16. 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

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

    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:
    1. Private Sub Form_Load()
    2.     Dim lngIdx As Long
    3.     Dim oNode As Node
    4.    
    5.     With Me.TreeView1
    6.         .LineStyle = tvwRootLines
    7.         For lngIdx = 1 To 3
    8.             Set oNode = .Nodes.Add(, , , "Root " & lngIdx)
    9.             oNode.ForeColor = vbRed
    10.             oNode.Expanded = True
    11.         Next
    12.    
    13.         For lngIdx = 1 To 3
    14.             'VB Color constants
    15.             Set oNode = .Nodes.Add(lngIdx, tvwChild, , "Parent " & lngIdx)
    16.             oNode.ForeColor = vbBlue
    17.            
    18.             'or use the RGB function
    19.             Set oNode = .Nodes.Add(lngIdx, tvwChild, , "Parent " & lngIdx)
    20.             oNode.ForeColor = RGB(0, 0, 172)
    21.         Next
    22.    
    23.     End With
    24. End Sub

  16. #16

    Thread Starter
    Member
    Join Date
    Feb 2006
    Posts
    61

    Talking 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
  •  



Click Here to Expand Forum to Full Width