|
-
May 28th, 2013, 11:11 PM
#1
Thread Starter
Junior Member
comparing two datagridviews
Hello there!
I would appreciate any help with the following problem: I have two tables: one, which would be the "wish table", and another, which would be the "supplier table". Okay, first, I would select items in the first table, that hasn't values, and search the second table with the correspondent items, their values and the different suppliers. Then I would compare the sum values of the matches, and display the information like "The search of your items returns the sum "x" from the "y" supplier...
Here, it is an example of my datatables/dgview:
Table1
idProduct Item
1 Item A
1 Item B
2 Item C
2 Item D
Table 2
idProduct Item Price IdSupplier
1 Item A 10.00 1
1 Item B 20.00 1
2 Item C 30.00 1
2 Item D 40.00 1
1 Item A 20.00 3
1 Item B 30.00 3
2 Item C 40.00 3
2 Item D 50.00 3
After a query that brings the lowest prices from each idSupplier, then I make an array with the number of idSuppliers. I do a loop though this array to put the data into two Lists: one for the supplier IDs and one for the sums of the prices, then convert each List to an array and then use Array.Sort to sort both arrays using the sums as the keys.
Code:
Dim idSupplier As List(Of Integer) = New List(Of Integer)
Dim sumValues As List(Of Decimal) = New List(Of Decimal)
'Dim item As List(Of String) = New List(Of String)
Dim value As Decimal
'Dim item1 As String
For Each element In SupplierArray
'For i = 1 To j
value = 0
For Each col As DataGridViewRow In dg2.Rows
If col.Cells(3).Value = element And col.Cells(2).Value > 0.0 Then
value = value + CDec(col.Cells(2).Value)
'item1 = col.Cells(1).Value.ToString
'item.Add(item1)
End If
'If value = 0 And col.Cells(2).Value = 0 Then
'Exit Sub ' It's not working
'End If
Next
sumValues.Add(value)
idSupplier.Add(element)
Next
' Next i
Dim idSupplierArray() = idSupplier.ToArray()
Dim sumValuesArray() = sumValues.ToArray()
Array.Sort(sumValuesArray, idSupplierArray)
'Dim itemArray() = item.ToArray()
'Dim itemNumero = itemArray.Length
So, I would like to return the number of Items of wich idSupplier from dg2 and compare with the Items from the dg1. Any suggestions?
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|