I have a TreeView control showing a root node per table.
For each of those root nodes I have a list of fields within the table that node represents as the 1st-level children of that root node.
The user drills in, finding the field theyâre after, then double-clicks it to add that
Table.Field entry to a List Box.
Following that, I want to remove that field from the display of the TreeView, without removing it from the nodes collection.
Following is the code I tried to accomplish this. It does not do what I need; the node stays in the
display, saying âneener, neener, neener!â at me...
Code:
Private Sub tvDBObjects_DblClick()
On Error GoTo Er
Dim tv As TreeView ' Create an early-bound variable
Dim nd As Node: Dim ThisItem As Long
Dim s As String: Dim NextItem As Long
Set tv = tvDBObjects.Object ' Set a reference to the TreeView
' in the early-bound variable.
Set nd = tv.SelectedItem.Parent ' Will raise Error #91 (object
' or with block not selected) if
' this is a root, causing a
' graceful exit, taking no action.
' Provide for two ListBox conditions:
' 1. No data in the ListBox yet;
' 2. Already have some data
s = lstColumns.RowSource
If s <> "" _
Then s = s & "; "
' Update the List Box. ColWidths are 0";2.5"
' Having the index to the node this datum came
' from permits âputting it backâ later, if need be.
' nd holds the name of the table.
' This concat generates: "##"; "tblName.fld"
lstColumns.RowSource = s & _
"""" & tv.SelectedItem.Index & """; """ & _
nd & "." & tv.SelectedItem & """"
' Assess the situation
ThisItem = tv.SelectedItem.Index
NextItem = tv.Nodes(ThisItem).Next.Index
' Move the focus
tv.Nodes(NextItem).Selected = True
tv.Nodes(ThisItem).Visible = False ' Expected the node to dissappear
' from the tree here
tv.Refresh ' Added this stmt; no help.
Rs:
Exit Sub
Er: Exit Sub [green]' Exit Sub will reset the error;
' built-in VB behavior.
End Sub
How can I make this child node disappear, while keeping it in the collection?
What is the intended use of .Nodes(
index).Visible?
You can see the behavior I am after in Excel's query builder.
Select a cell, go to the Data menu, and select "Get external data" > "New Database Query..."