Datagridview - check for duplicates( or more) and put in other cell the total
|12/26/2016 |9A |Christmas Day
|3/25/2016 |9A |Good Friday
|3/28/2016 |AS |Easter Monday
|12/26/2016 |AS |St. Stephen's Day
|3/25/2016 |AS |Easter Monday
|1/1/2016 |AS |New Year's Day
|12/26/2016 |BE |Christmas
|1/1/2016 |BZ |New Year's Day
|2/9/2016 |BZ |Carnival
|5/26/2016 |BZ |Corpus Christ
|4/21/2016 |BZ |Tiradentes Day
|12/27/2016 |CA |Boxing Day
|10/10/2016 |CA |Thanksgiving
hey there. i have a datagridview like this example, and i want to add a new column to "output" the duplicated values of column 2 when the date(column1) is the same.
|12/26/2016 |9A |Christmas Day | 9A AS BE
|3/25/2016 |9A |Good Friday | 9A
|3/28/2016 |AS |Easter Monday | AS
|12/26/2016 |AS |St. Stephen's Day | 9A AS BE
|3/25/2016 |AS |Easter Monday | AS
|1/1/2016 |AS |New Year's Day | AS BZ
|12/26/2016 |BE |Christmas | 9A AS BE
|1/1/2016 |BZ |New Year's Day | AS BZ
|2/9/2016 |BZ |Carnival | BZ
|5/26/2016 |BZ |Corpus Christ | BZ
|4/21/2016 |BZ |Tiradentes Day | BZ
|12/27/2016 |CA |Boxing Day | CA
|10/10/2016 |CA |Thanksgiving | CA
i have this code:
Code:
For i = 0 To DataGridView1.RowCount - 1
For j = 0 To DataGridView1.RowCount - 1
If DataGridView1.Rows(i).Cells(0).Value = DataGridView1.Rows(j).Cells(0).Value Then
DataGridView1.Rows(i).Cells(3).Value = DataGridView1.Rows(i).Cells(1).Value + DataGridView1.Rows(j).Cells(1).Value
End If
If i = j Then
DataGridView1.Rows(i).Cells(3).Value = DataGridView1.Rows(i).Cells(1).Value
End If
Next
Next
but it only adds 2 values, not when there's 3.. ty
Re: Datagridview - check for duplicates( or more) and put in other cell the total
Code:
Private Sub Button3_Click(sender As Object, e As EventArgs) Handles Button3.Click
Dim i As Integer
Dim j As Integer
For i = 0 To DataGridView1.RowCount - 1
For j = 0 To DataGridView1.RowCount - 1
If i > j Then
'If DataGridView1(0, i).Value = DataGridView1(0, j).Value Then
If DataGridView1(0, i).Value = DataGridView1(0, j).Value Then
DataGridView1(3, i).Value = DataGridView1(1, i).Value + DataGridView1(1, j).Value
End If
End If
If i < j Then
'If DataGridView1(0, i).Value = DataGridView1(0, j).Value Then
If DataGridView1(0, i).Value = DataGridView1(0, j).Value Then
DataGridView1(4, i).Value = DataGridView1(1, i).Value + DataGridView1(1, j).Value
End If
End If
If i = j Then
DataGridView1(5, i).Value = DataGridView1(1, i).Value
End If
Next
Next
End Sub
this is the best approach i have so far .. help?