Subject: TreeView.Nodes(x).Visible & VB6
Posted By: BrianWren Post Date: 8/23/2006 4:22:11 PM
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...
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..."
Reply By: BrianWren Reply Date: 8/28/2006 4:03:00 PM
Well then (since there are no takers) is there a website (or other nline resource) that really “unpacks”
the functionality of the TreeView control?

(BTW:  Found at

       msdn.microsoft.com/library/default.asp?url=/library/en-us/vbcmn98/html/vbprovisiblepropertyactivexcontrols.asp:

           The Visible property of the Treeview control's Node object is read-only at run time.
)

Go to topic 48841

Return to index page 191
Return to index page 190
Return to index page 189
Return to index page 188
Return to index page 187
Return to index page 186
Return to index page 185
Return to index page 184
Return to index page 183
Return to index page 182