Click here to Skip to main content
15,885,278 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have a datagrid connected to a database with ADO .Net, when I execute the code it adds rows to the 2nd datagrid as the number of cells are in style beige, I want to add one row and the cells that in color beige (they meet the requirment and become backcolor beige, it is a date check code), it adds not 1 row and the selected cells but 1 row for each selected cell even if they are in the same row, I want 1 row for one row of the 1st datagridview, I know it is somewhere in the fro statments but cannot figure it out where.
code of creating rows in 2nd datagridview
VB
Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
        Dim c, t, d, g, h, i As Integer
       Form2.DataGridView1.Columns.Clear()
        For t = 0 To DataGridView1.Columns.Count - 1
            Form2.DataGridView1.Columns.Add(DataGridView1.Columns(t).Clone())
        Next
        c = 0
        d = 0
        For c = 0 To DataGridView1.Rows.Count - 1
            For d = 0 To DataGridView1.Rows(c).Cells.Count - 1
                If DataGridView1.Rows(c).Cells(d).Style.BackColor = Color.Beige Then
                    Form2.DataGridView1.Rows.Add(Me.DataGridView1.Rows(c).Cells(0).Value, Me.DataGridView1.Rows(c).Cells(1).Value, Me.DataGridView1.Rows(c).Cells(2).Value, Me.DataGridView1.Rows(c).Cells(3).Value, Me.DataGridView1.Rows(c).Cells(4).Value, Me.DataGridView1.Rows(c).Cells(5).Value, Me.DataGridView1.Rows(c).Cells(6).Value, Me.DataGridView1.Rows(c).Cells(7).Value, Me.DataGridView1.Rows(c).Cells(8).Value, Me.DataGridView1.Rows(c).Cells(9).Value, Me.DataGridView1.Rows(c).Cells(10).Value, Me.DataGridView1.Rows(c).Cells(11).Value, Me.DataGridView1.Rows(c).Cells(12).Value, Me.DataGridView1.Rows(c).Cells(13).Value)
                                  End If
            Next
        Next
end sub


and code for date check if nessecary:
VB
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        Dim dt As New Date
        Dim i, g As New Int32
        i = 0
        g = 0
        Dim workTable As DataTable = New DataTable("Customers")
        For Each row As DataGridViewRow In DataGridView1.Rows
         For c As Int32 = 1 To DataGridView1.ColumnCount - 1
           If row.Cells(c).Value IsNot DBNull.Value Then
             dt = Date.Parse(row.Cells(c).Value)
              If (Date.Today >= (dt.AddMonths(-1))) And (Date.Today <= dt) Then
               row.Cells(c).Style.BackColor = Color.Beige
                i = i + 1
           End If
           End If
         Next
        Next
  MessageBox.Show("ΥΠΑΡΧΟΥΝ : " + i.ToString + " ΕΓΓΡΑΦΕΣ ΣΤΑ ΑΥΤΟΚΙΝΗΤΑ", "ΗΜΕΡΟΜΗΝΙΑ EXPIRED")
end sub
Posted

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