PlanetSquires Forums

Please login or register.

Login with username, password and session length
Advanced search  

Author Topic: treeview parent text node  (Read 375 times)

jermy

  • Junior Member
  • **
  • Posts: 60
treeview parent text node
« on: May 26, 2020, 05:14:33 PM »

Hi people

how do i get the parent text node of the selected child node in a treeview?.

Code: [Select]
''
''
Function frmMain_TreeView1_MouseDown( ByRef sender As wfxTreeView, ByRef e As EventArgs ) As LRESULT

if e.LButton then

      ' Determine if we have clicked on a TreeNode
      dim as wfxPoint wpt = e.pt
      wpt.Convert( frmMain.TreeView1.hWindow )
     
      ' Only continue if the TreeNode is valid
      dim byref TreeNode as wfxTreeNode = sender.GetNodeAt( wpt )
      if TreeNode.hNode = 0 then exit function
     
      ' Ensure that the node left clicked on is now selected
      TreeNode.Selected = true
     
      ' // Retrieve the selected item
      DIM hItem AS HTREEITEM = TreeView_GetSelection(frmmain.treeview1.hWindow)
     
      ' // Retrieve the text of the selected item
      DIM wszText AS WSTRING * 260
      TreeView_GetItemText(frmmain.treeview1.hWindow, hItem, @wszText, 260)
      print wszText & " childnode"

end if

    Function = 0
End Function


Logged

Paul Squires

  • Administrator
  • Guru Member
  • *****
  • Posts: 9313
  • Windows 10
    • PlanetSquires Software
Re: treeview parent text node
« Reply #1 on: May 26, 2020, 05:37:26 PM »

You can use Jose's function found in his WinFBX library (look at the Afx\AfxCtl.inc file):

Code: [Select]
' ========================================================================================
' Retrieves the text of the parent item of the specified tree-view item.
' Usage example:
' DIM wszText AS WSTRING * 260
' TreeView_GetParentText(hTreeView, hItem, @wszText, 260)
' AfxMsg(wszText)
' Returns TRUE if successful, or FALSE otherwise.
' ========================================================================================
PRIVATE FUNCTION TreeView_GetParentText (BYVAL hwndTV AS HWND, BYVAL hItem AS HTREEITEM, BYVAL pwszText AS WSTRING PTR, BYVAL cchTextMax AS LONG) AS BOOLEAN
   IF pwszText = NULL THEN EXIT FUNCTION
   DIM hNode AS HTREEITEM = TreeView_GetNextItem(hwndTV, hItem, TVGN_PARENT)
   IF hNode THEN FUNCTION = TreeView_GetItemText(hwndTV, hNode, pwszText, cchTextMax)
END FUNCTION
' ========================================================================================
Logged
Paul Squires
PlanetSquires Software
WinFBE Editor and Visual Designer

Paul Squires

  • Administrator
  • Guru Member
  • *****
  • Posts: 9313
  • Windows 10
    • PlanetSquires Software
Re: treeview parent text node
« Reply #2 on: May 26, 2020, 05:54:40 PM »

Also, I'm curious as to why you are doing this in the MouseDown event rather than in the Click event.

Code: [Select]
''
''
Function frmMain_TreeView1_Click( ByRef sender As wfxTreeView, ByRef e As EventArgs ) As LRESULT
   DIM wszText AS WSTRING * 260
   TreeView_GetParentText( sender.hWindow, sender.TreeNode.hNode, @wszText, 260 )
   
   ? "Click: "; sender.TreeNode.Text, e.RButton
   ? "Parent node text: "; wszText
   Function = 0
End Function
Logged
Paul Squires
PlanetSquires Software
WinFBE Editor and Visual Designer

jermy

  • Junior Member
  • **
  • Posts: 60
Re: treeview parent text node
« Reply #3 on: May 26, 2020, 05:59:56 PM »

The code is partly from the Winfbe editor help file, indeed click event is more logical
Logged