• Welcome to PlanetSquires Forums.
 

treeview parent text node

Started by jermy, May 26, 2020, 05:14:33 PM

Previous topic - Next topic

jermy

Hi people

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


''
''
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




Paul Squires

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


' ========================================================================================
' 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
' ========================================================================================

Paul Squires
PlanetSquires Software
WinFBE Editor and Visual Designer

Paul Squires

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


''
''
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

Paul Squires
PlanetSquires Software
WinFBE Editor and Visual Designer

jermy

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