Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How do I get the containership of controls 2

Status
Not open for further replies.

granni

Programmer
Nov 8, 2000
36
SG
Does anyone know how do I trace the containership of each control (at runtime) to the top most container, including the Window?

Similarly I need to be able to trace from the window down to the form and to the individual controls

Thanks
:-X
 
Hi

This example populates a treeview for simplicity sake. It could easily have been a userdefined hierarchical structure, MSHFlexGrid,MS Outline etc.
For those of you who don't now, the treeview control can be found under Microsoft Windows Common Controls...it's part of a package of controls.

What you need to do to run this example.
1)Add a TreeView control to the form you want to query. (Keep the defaults)
2)Add a command button (Keep the defaults)

Paste the code (hopefully there'snot too many compilation errors.) ;-)

This also works with control arrays and the error handling and code is a bit sloppy as I just slapped this quickly together.
It needs work to be more efficient and generic. As soon as you have the end product mail it to I'm sure I'll use it sometime.

Have fun
caf
Code:
Private Sub Command1_Click()

   Const ControlDoesntHaveIndexProperty% = 343

   Dim objCurrentNode   As Node
   Dim objNode          As Node
   Dim objControl       As Control
   Dim sName            As String

   On Error GoTo Hell

   With TreeView1
      .Style = tvwTreelinesPlusMinusPictureText
      .BorderStyle = vbFixedSingle
      .LineStyle = tvwRootLines
   End With

   Set objCurrentNode = TreeView1.Nodes.Add( _
                                    , , Me.Name, Me.Name)

   For Each objControl In Me.Controls
      sName = objControl.Name
      sName = sName & "(" & objControl.Index & ")"

      For Each objNode In TreeView1.Nodes
         If objControl.Container.Name = objNode.Key Then
            Set objCurrentNode = TreeView1.Nodes.Add( _
                       objNode.Key, tvwChild, sName, sName)
            Exit For
         End If
      Next
   Next

Exit Sub

Hell:
   If Err.Number = ControlDoesntHaveIndexProperty Then
      Resume Next
   Else
      MsgBox Err.Description, , Err.Number
   End If

End Sub
 
Okie, i got it, thanks, guess i need to model this now beyong the form level to the windows level. Here's my app, its really a sample form, but just to show that ur has been a great help. I try to email u a working prototype
 
Oh silly me i forgot to login, that reply on a sample form is mine, thanks,btw how do i mail u my app?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top