Click here to Skip to main content
15,898,992 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have a 2 dimensional array: myGridData[49,5].
The data was collected from 7 datagridviews, each with 7 rows x 5 columns.
I want to re-populate the 7 datagridviews with the data back from the array.

I have tried this:

C#
var rowCount = myGridData.GetLength(0);
var rowLength = myGridData.GetLength(1);

var dgvs = new[] { dgv6, dgv5, dgv4, dgv3, dgv2, dgv1, dgv0, };

dgvs[0].ColumnCount = 5;
dgvs[1].ColumnCount = 5;
dgvs[2].ColumnCount = 5;
dgvs[3].ColumnCount = 5;
dgvs[4].ColumnCount = 5;
dgvs[5].ColumnCount = 5;
dgvs[6].ColumnCount = 5;

for (int rowIndex = 0; rowIndex < rowCount - 1; ++rowIndex)
{
    for (int x=0;x<7;x++)   //grids
    {
        var row = new DataGridViewRow();

            for (int columnIndex = 0; columnIndex < rowLength; ++columnIndex)
            {
                    row.Cells.Add(new DataGridViewTextBoxCell()
                    {
                            Value = myGridData[rowIndex, columnIndex]
                    });
            }
        dgvs[x].Rows.Add(row);

    }
}


but what I get back is 49 rows in each grid with incorrect data.
Any help would be appreciated.
Posted
Comments
virusstorm 25-Jun-15 15:41pm    
Instead of using arrays, why not create an object that represents the data in grid? You can bind the grid to this object and I suspect it will be far easier to debug.
kapeda 25-Jun-15 21:21pm    
I am not sure I understand your comment virusstorm? Do you mean create 7 objects (for each grid) then cycle through each object and bind to each grid?

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