Hello, i accidentally deleted the previous question but my problem istn solved yet so....
I had some great help on your site, found the solution to some stuff i was struggling with, but now i got a question myself:
I used the code from this page: link [^]
and it works great. it adds new coloms the the 2nd datagrid and fills them. However, Is it possible to have it add the selected data into new rows in excisting columns? and then so that it wil automatically create a new row if row 1 and 2(for example) are already populated(or is this not possible? )
That way i can fill a datagridview with data from 2 other datagridviews which will save me quite some time.
Update
Per request, the code i already tried. It works if you want to fill a empty dgv, but i want to fill a allready populated dgv.
Private Sub btncopy_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btncopy.Click
Dim c, t As Integer
For t = 0 To DataGridView1.Columns.Count - 1
DGV2.Columns.Add(DataGridView1.Columns(t).Clone())
Next
For c = 0 To DataGridView1.Rows.Count - 1
If DataGridView1.Rows(c).Cells(4).Value = True Then
DGV2.Rows.Add(DataGridView1.Rows(c).Cells(0).Value, DataGridView1.Rows(c).Cells(1).Value)
DGV2.Columns(2).Visible = False
DGV2.Columns(3).Visible = False
End If
Next
End Sub
And after some comments i got this code.
For i As Integer = 0 To Rantsoengrid.Rows.Count - 1
If Rantsoengrid.Rows(i).Cells(3).Value = True Then
DGV2.Rows.Add(Rantsoengrid.Rows(i).Cells(3).Value, _
Rantsoengrid.Rows(i).Cells(2).Value, _
Rantsoengrid.Rows(i).Cells(4).Value, _
Rantsoengrid.Rows(i).Cells(6).Value)
End If
Next
End Sub
update
Okay, stupid me. referenced to the wrong datagridview in the code.
Now all that remains is converting the data from a string to boolean. (of which i know its true or false)i wil ltry to figure that one out myself but ofcourse, if you know the answer, feel free to post it for future reference (for other people)
De conversie van tekenreeks naar type Boolean is ongeldig.
And, if i use the cells from the original datagridvieuw(0,1,2,3) instead of the ones i want to copy the data to (2,3,4,6) then i get the error that the programm cant add rows because the datagridview is databound.(removing the binding is not a option, due to the other data in the datagridview)
Okay, update because i did solve some things now, but not this one.
I think the way we need to work from is the error
"Invalid Operationexception was unhandled"
This is because the errorreport states that it cannot copy the data to a databound datagridview. Is there any way around this?