Bill Of Material

I am looking for some example code to explode a multi level Bill Of Material.

My Table structure is as Follows:

ParentID
ChildID
Level

An Individual BOM might have several levels.

I need one that will work with either Access or SQL Server.

Any examples of a recursive explosion would be great.

Thanks in advance

Andy
andytauberAsked:
Who is Participating?
 
raterusConnect With a Mentor Commented:
This is how I've done the same thing in a program of mine, I've tried to comment it... "GetNodes()" is your starting Sub, you'll have to adapt it for your treeview controls, but if it works like microsofts, this shouldn't be a problem.

    Private Sub GetNodes()
      'Do any code to fill "dt", a datatable with valid information (childID, parentID essential)
      Dim dt as DataTable = FillDataTable()
      Dim rootParentID as string = "0"      'this is the parentID of your root nodes

      'tv is my treeview
        tv.Nodes.Clear()

        Dim drs As DataRow() = dt.Select("[parentID] = '" & rootParentID & "'")
        For Each dr As DataRow In drs
            Dim node As TreeNode = New TreeNode
            node.Text = CStr(dr("ChildID"))
            FillNodes(dt, node.NodeData, node)
            tv.Nodes.Add(node)
        Next
    End Sub

    Private Sub FillNodes(ByVal dt As DataTable, ByVal parentID As String, ByRef node As TreeNode)
        Dim drs As DataRow() = dt.Select("[parentID] = '" & parentID & "'")
        For Each dr As DataRow In drs
            Dim newNode As TreeNode = New TreeNode
            newNode.Text = CStr(dr("ChildID"))
            FillNodes(dt, newNode.NodeData, newNode)
            node.Nodes.Add(newNode)
        Next
    End Sub
0
 
andytauberAuthor Commented:
I shoud add that i'm looking for a asp.net vb example.

Thanks
0
 
raterusCommented:
how would you like to display this to the user?
0
The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

 
andytauberAuthor Commented:
I want ot put it in a treeview
0
 
raterusCommented:
is this the microsoft treeview control?
0
 
andytauberAuthor Commented:
I'm using componentart. I just need to get the structure into a dataset.
0
 
raterusCommented:
What exactly are you trying to do, I'm confused

Query DB and display Bill of Sale in Treeview
or
Traverse Treeview and insert into database?
0
 
andytauberAuthor Commented:
I want to display the bill in a treeview

I am looking for the code to explode it into a dataset.
0
 
raterusCommented:
a dataset is still a flat-file representation, you can fill it like any other sql query.  When you fill the treeview is when you'll use recursion.  I can help you with that part, but I'll need to know how you actually fill the treeview. (If it has nodes, and you can add one node to another in code, we're set)
0
 
andytauberAuthor Commented:
Yes each node represents an item. The nodes need to reflect the relationship. I.E.

Parent
   Child1
   Child 2
      Child 3
      Child 4
         Child 5
   Child 6
etc....
0
 
raterusCommented:
Is there going to be a root node in the treeview, or could there be many top-level nodes?  I'm looking at a project now where I'm doing the exact same thing, only there isn't a root node, per se.
0
 
andytauberAuthor Commented:
There are many top levels

+ Parent1
+ Parent 2
+ Parent 3
0
 
andytauberAuthor Commented:
Thanks This works great!!!!
0
All Courses

From novice to tech pro — start learning today.