It's little bit of messy code, but it's doable...:)
' iterate the partlist rows
For i = counter To oPartslist.PartsListRows.Count
orow = oPartslist.PartsListRows.Item(i)
'write values for the different columns
For j = 1 To oPartslist.PartsListColumns.Count
Dim ocell As Inventor.PartsListCell
ocell = orow.Item(j)
If j = 1 Then
Me.DataGridView1.Rows(i - 1).Cells(0).Value = ocell.Value
End If
If j = 2 Then
Me.DataGridView1.Rows(i - 1).Cells(2).Value = ocell.Value
End If
If j = 3 Then
Me.DataGridView1.Rows(i - 1).Cells(1).Value = ocell.Value
End If
If j = 6 Then
Me.DataGridView1.Rows(i - 1).Cells(6).Value = ocell.Value
End If
If j = 7 Then
Me.DataGridView1.Rows(i - 1).Cells(4).Value = ocell.Value
'multiply the value from cell 2 with the value from cell 4
weight1 = Convert.ToDecimal(DataGridView1.Rows(i - 1).Cells(2).Value)
weight3 = oPartslist.PartsListRows(i).Item(7).Value.ToString
'delete the kg from value
weight3 = weight3.Substring(0, weight3.Length - 2)
weight2 = Convert.ToDouble(weight3)
totweight = weight1 * weight2
DataGridView1.Rows(i - 1).Cells(5).Value = totweight & " kg"
'add the weight to the total weight
totaal = totaal + totweight
End If
If j = 8 Then
If oPartslist.PartsListRows(i).Item(j).Value = "" Then
Me.DataGridView1.Rows(i - 1).Cells(3).Value = "-"
Else
Me.DataGridView1.Rows(i - 1).Cells(3).Value = ocell.Value
End If
End If
Next j
' check to see if it's a subassembly
If orow.Expandable = True Then
'get the number of rows for the subassembly
loopcount = getloopcount(orow)
'write the values to the gridview
writesub(loopcount, i)
Me.DataGridView1.Rows(i - 1).Cells(7).Value = "SEE DETAILS"
End If
Me.ProgressBar1.PerformStep()
Next i
'write total weight to gridview
Me.DataGridView1.Rows(begincount).Cells(4).Value = "TOTAL : "
Me.DataGridView1.Rows(begincount).Cells(5).Value = totaal & " kg"
Me.DataGridView1.Rows(begincount).Cells(4).Style.Font = New System.Drawing.Font(Control.DefaultFont, FontStyle.Bold)
Me.DataGridView1.Rows(begincount).Cells(5).Style.Font = New System.Drawing.Font(Control.DefaultFont, FontStyle.Bold)
Me.DataGridView1.Rows(begincount).DefaultCellStyle.BackColor = Color.DarkGray
End Sub
Sub writesub(loopcount As Integer, i As Integer)
Dim startitem As Integer
'remember the startrow
startitem = i
' read the rows in subassembly
For a = 0 To loopcount
orow = oPartslist.PartsListRows.Item(i)
'Write the different values for the columns
For j = 1 To oPartslist.PartsListColumns.Count
If j = 1 Then
Me.DataGridView1.Rows(startrow).Cells(0).Value = oPartslist.PartsListRows(i).Item(j).Value
If a = 0 Then
Me.DataGridView1.Rows(startrow).Cells(0).Style.Font = New System.Drawing.Font(Control.DefaultFont, FontStyle.Bold)
End If
End If
If j = 2 And a > 0 Then
Me.DataGridView1.Rows(startrow).Cells(2).Value = oPartslist.PartsListRows(i).Item(j).Value
End If
If j = 3 Then
Me.DataGridView1.Rows(startrow).Cells(1).Value = oPartslist.PartsListRows(i).Item(j).Value
If a = 0 Then
Me.DataGridView1.Rows(startrow).Cells(1).Style.Font = New System.Drawing.Font(Control.DefaultFont, FontStyle.Bold)
End If
End If
If j = 6 And a > 0 Then
Me.DataGridView1.Rows(startrow).Cells(6).Value = oPartslist.PartsListRows(i).Item(j).Value
End If
If j = 7 And a > 0 Then
Me.DataGridView1.Rows(startrow).Cells(4).Value = oPartslist.PartsListRows(i).Item(j).Value
End If
If j = 8 And a > 0 Then
If oPartslist.PartsListRows(i).Item(j).Value = "" Then
Me.DataGridView1.Rows(startrow).Cells(3).Value = "-"
Else
Me.DataGridView1.Rows(startrow).Cells(3).Value = oPartslist.PartsListRows(i).Item(j).Value
End If
End If
Next j
If a > 0 Then
weight1 = Convert.ToInt32(DataGridView1.Rows(startrow).Cells(2).Value)
weight3 = oPartslist.PartsListRows(i).Item(7).Value.ToString
If Not weight3 = "" Then
weight3 = weight3.Substring(0, weight3.Length - 2)
weight2 = Convert.ToDouble(weight3)
totweight = weight1 * weight2
totalsub = totalsub + totweight
DataGridView1.Rows(startrow).Cells(5).Value = totweight & " kg"
End If
End If
'this is the part where it goes wrong......!!
If orow.Expandable = True And a > 0 Then
loopcount = getloopcount(orow)
'remember the row where we left
rowexit = startrow
' add extra rows for writing the values for the subassembly
startrow = startrow + extrarow
writesub(loopcount, i)
i = i + 1
startrow = startrow + 1
startrow = rowexit
Else
startrow = startrow + 1
i = i + 1
End If
Next
orow = oPartslist.PartsListRows.Item(startitem)
If orow.Expanded = True Then
orow.Expanded = False
startrow = startrow + extrarow
Else startrow = startrow + 1
End If
End Sub
Function getloopcount(orow As Inventor.PartsListRow)
countbefore = oPartslist.PartsListRows.Count
orow.Expanded = True
countafter = oPartslist.PartsListRows.Count
countsubtracted = countafter - countbefore
extrarow = countsubtracted + 1
ListBox1.Items.Add(extrarow)
Return countsubtracted
End Function