Click here to Skip to main content
15,888,113 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hi
i have this code
i want to see rows that are the same as each other in grdfloopy.
and show them in grdfloopy1.:confused::confused: :sigh: :sigh:

VB
Private Sub selectghabz()
Dim a As HomePage = New HomePage
Dim i As Integer
Dim j, k As Integer
k = 0
For i = 0 To grdFloppy.RowCount - 1
For j = i + 1 To grdFloppy.RowCount - 1
If (grdFloppy.Item(3, i).Value = grdFloppy.Item(3, j).Value) And (grdFloppy.Item(4, i).Value = grdFloppy.Item(4, j).Value) Then

If (grdFloppy.Item(0, i).Value <> grdFloppy.Item(0, j).Value) Then
grdFloppy1.Rows.Add()
grdFloppy1.Item(0, k).Value = grdFloppy.Item(0, i).Value
grdFloppy1.Item(1, k).Value = grdFloppy.Item(1, i).Value
grdFloppy1.Item(2, k).Value = grdFloppy.Item(2, i).Value
grdFloppy1.Item(3, k).Value = grdFloppy.Item(3, i).Value
grdFloppy1.Item(4, k).Value = grdFloppy.Item(4, i).Value
grdFloppy1.Item(5, k).Value = grdFloppy.Item(5, i).Value
k = k + 1
End If
End If
Next
Next
End Sub



tnxxxxxxxxxxx
Posted
Updated 17-Sep-10 18:33pm
v2

This works for me...

VB
For Each dr As DataGridViewRow In grdFloppy.Rows
      For Each dr2 As DataGridViewRow In grdFloppy.Rows
        If dr2.Index > dr.Index Then
          checkExists(dr, dr2)
        End If
      Next
    Next


VB
Private Sub checkExists(ByVal dr As DataGridViewRow, _
                          ByVal dr2 As DataGridViewRow)
    ' Compare the two rows
    If dr.Cells(3).Value.ToString = dr2.Cells(3).Value.ToString And _
              dr.Cells(4).Value.ToString = dr2.Cells(4).Value.ToString And _
              dr.Cells(0).Value.ToString = dr2.Cells(0).Value.ToString Then
      For Each drow As DataGridViewRow In grdFloppy1.Rows
        ' Check that row doesn't already exist in grdFloppy1
        If drow.Cells(3).Value.ToString = dr.Cells(3).Value.ToString And _
                           drow.Cells(4).Value.ToString = dr.Cells(4).Value.ToString And _
                           drow.Cells(0).Value.ToString = dr.Cells(0).Value.ToString Then
          Exit Sub
        End If
      Next
      ' Add the new row to grdFloppy1
      grdFloppy1.Rows.Add(New Object() {dr.Cells(0).Value, dr.Cells(1).Value, _
                                        dr.Cells(2).Value, dr.Cells(3).Value, _
                                        dr.Cells(4).Value})
    End If
  End Sub
 
Share this answer
 
tnx
by i want to find rows in DataGridViewRow1(:grdfloopy1) that are the same az each other in same fileds and then show these 2 rows in DataGridViewRow2(:grdfloopy1).
plzzzzzzzzzzzzz help me soon
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900