Hi All
I am populating a listbox based on an item selected in another listbox. But wat i get is huge number of entries in the populated listbox. It basically contains the folders anf all files present in a particular project workspace. (so as n when the count of folders/files increases..it wud get even messy)

What i think would be ideal here is make the entries in the listbox expandable(like the entries in C drive in My Computer). That is the first level of folders/files would only appear initially. and then on clickin on their respective checkboxes their sub items would appear.
Can anyone tell me hoe this can be done..any leads on this pls?

also It wud be grt if I select the topmost checkbox, All the items under it get selected.

Any leads on this??

Thanks In advance:)

Dani AI

Generated

As pointed out, a TreeView is the right control for hierarchical, expandable lists with checkboxes. You can drop the TreeView (Microsoft Windows Common Controls) onto a normal VB6 form and compile a standard EXE — there is no need to change your project type to an ActiveX EXE. As hinted, store an ID/path with each node (use the node's Tag) rather than trying to mirror everything with parallel arrays.

Practical approach:

  • Add the TreeView via Project → Components and enable its Checkboxes property.
  • On startup, populate only top-level folders (root nodes). Put the folder path in each node.Tag and, if a folder may have children, add a small “not-loaded” marker (or a dummy child) instead of loading everything at once.
  • When a node is expanded, check your marker; if children are not loaded, enumerate the folder (Dir or FileSystemObject), add child nodes and set their Tag. This lazy-loading keeps the UI responsive even for large trees.
  • Use the NodeCheck event to cascade the parent’s checked state to all descendants with a small recursive routine.

Example routine (VB-style) to propagate checks downwards:

Sub SetChildChecks(n As Node, state As Boolean)
    Dim c As Node
    Set c = n.Child
    Do While Not c Is Nothing
        c.Checked = state
        SetChildChecks c, state
        Set c = c.Next
    Loop
End Sub

Private Sub TreeView1_NodeCheck(ByVal Node As Node)
    SetChildChecks Node, Node.Checked
End Sub

Packaging notes and gotchas:

  • Distribute and register mscomctl.ocx on target machines (on 64‑bit Windows use SysWOW64 and regsvr32). Missing/broken references to the common controls are the usual cause of compile/runtime errors.
  • VB6 TreeView has no built‑in tri‑state checkbox; implement parent-state logic yourself if you need “partial” selection feedback.
  • For collecting selections, walk the Nodes collection and read Tag for each checked node instead of re-scanning the filesystem.

Hi josephdluna,
I have not been able to open that link.Dunno why.
Can u pls elaborate a bit on that?

One more thing I wud like to add here
I am developing a utility (std exe). so in order to use this tree view control, do I need to make it as someother exe type..like active x exe etc...???

Hi All
I am populating a listbox based on an item selected in another listbox. But wat i get is huge number of entries in the populated listbox. It basically contains the folders anf all files present in a particular project workspace. (so as n when the count of folders/files increases..it wud get even messy)

What i think would be ideal here is make the entries in the listbox expandable(like the entries in C drive in My Computer). That is the first level of folders/files would only appear initially. and then on clickin on their respective checkboxes their sub items would appear.
Can anyone tell me hoe this can be done..any leads on this pls?

also It wud be grt if I select the topmost checkbox, All the items under it get selected.

Any leads on this??

Thanks In advance:)

If I understand you well, an apropriate solution would be to define new type of variables that contains at leas two informations:
example:
Type MainListBox
List_ID as Integer
ItemOnList as String
End Type
Type PopulatedListBox
BelongsToList_ID as Integer
ItemOnList as String
End Type
Dim Items1 As MainListBox ' Or Dim Items1(1 To SomeNumber) as MainListBox
Dim Items2 As PopulatedListBox
' Now in a cycle that activates on List1_SelectionChange make a test to identify LIST_ID, and firts clear the populated list, and fill it with data whose items have BelongsToList_ID same as List_ID of the first list.
I hope I was helpfull

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.