I have a project in VB .net 2008 which stores dates in a database and I use datagridview, I compare the dates and if they match to some cretiria the cell bcolor becames beige code :
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
Dim dt As New Date
For Each row As DataGridViewRow In DataGridView1.Rows
For c As Int32 = 0 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
MessageBox.Show("ΥΠΑΡΧΕΙ ΕΓΓΡΑΦΗ ΣΤΑ ΑΥΤΟΚΙΝΗΤΑ", "ΗΜΕΡΟΜΗΝΙΑ EXPIRED")
End If
End If
Next
end sub
Next
I want to copy these cells in to a new datagridview with the same collumns but to copy only the cells that their color is beige, so far I cloned the datagridview but I copied either all cells code :
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
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
or the selected cells but not in their correct columns, this code copies the selected cell but puts them all in the first cell of the second datagrid, I want them to put in the correct column of the datagrid :
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
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(DataGridView1.Rows(c).Cells(d).Value)
end if
next
next
end sub
If I could create only the selected cells with their column name to the 2nd datagrid would be ok too. Or the whole row but to display only the selected cells.