Imagine that I have one Form1.DataGridView1 which contains severals rows and several columns.
So, the user has the possibility of adding more rows or columns.
-------Column1 | Column2 | Column3
row1---cell1-----cell2-----cell3
row2---cell1-----cell2-----cell3
row3---cell1-----cell2-----cell3
Now, I need to pass all this information to other Form2.DataGridView1. This new DataGridView doesn't contain any kind of data, so I need to add the Columns first.
For col As Integer = 0 To Form1.DataGridView1.Columns.Count - 1
Form2.DataGridView1.Columns.Add(col, "")
Next
Ok, no problem at all.
However, now I need to get all the rows and the specific cells in each column.
I tried so far (without success):
For R As Integer = 0 To Form1.DataGridView1.Rows.Count - 1
For C As Integer = 0 To Form1.DataGridView1.Columns.Count - 1
Dim row As String() = New String() {Form1.DataGridView1.Rows(R).Cells(C).Value}
Form2.DataGridView1.Rows.AddRange(row)
Next
Next
The problem is that instead of adding like this:
-------Column1 | Column2 | Column3
row1---cell1-----cell2-----cell3
row2---cell1-----cell2-----cell3
row3---cell1-----cell2-----cell3
It add like this:
-------Column1 | Column2 | Column3
row1---cell1-----
row2---cell2-----
row3---cell3-----
row4---cell1-----
row5---cell2-----
row6---cell3-----
I know the problem is in this line:
Dim row As String() = New String() {Form1.DataGridView1.Rows(R).Cells(C).Value}
But how can I solve it?

New Topic/Question
Reply




MultiQuote





|