I have a program that automatically generates a 2D grid of buttons and stores the grid in a nested list and I am trying to export this list to MS Excel. however the code that I am trying throws to many errors. I can get this working without using a list but I need to use a nested list in order to clear the list a populate it again if and when the size of the grid increases or decreases. Is the logic that I'm using even doable
As follows:
//This is not the complete code
List<List<Button>> buttonss = new List<List<Button>>();
List<Button> rowList = new List<Button>();
//Some method that creates a grid of buttons
buttons = new Button[row][];
for (int r = 0; r < row; r++)
{
buttons[r] = new Button[col];
buttonss.Add(rowList);
for (int c = 0; c < col; c++)
{
buttons[r][c] = new Button();
rowList.Add(buttons[r][c]);
}
}
The next thing that I want to do is ot export this list into excel.
The grid:

Button:
//Export to MS Excel button
private void btnExport_Click(object sender, EventArgs e)
{
ep.Do("sheet.xsl", rowList);//(ERROR 0)
}
Class:
//Export class
public void Do(string excelName, System.Collections.Generic.List<Button[][]> Grid)
{
for (int i = 0; i <= Grid.Count(); i++)
{
for (int j = 0; j <= Grid[i].Count(); j++)
{
AddData(i, j, Grid[i][j]);//(ERROR HERE [1])
}
}
//app.SaveWorkspace(excelName);
}
public void AddData(int row, int col, System.Collections.Generic.List<Button[][]> button)
{
if (button == null) return;
row++;
col++;
Range range = worksheet.Cells[row + 2, col + 2];
if (!defaultBackgroundIsWhite)
{
range.Interior.Color = button.BackColor.ToArgb();//(ERROR HERE[2])
}
else
range.Interior.Color = button.BackColor.Name != "Control" ? button.BackColor.ToArgb() : System.Drawing.Color.White.ToArgb();//(ERROR HERE)
// range.NumberFormat = "";
worksheet.Cells[row + 2, col + 2] = button.Text;//(ERROR HERE[3])
row--;
col--;
}
Errors: 0:Argument 2: cannot convert from 'System.Collections.Generic.List' to 'System.Collections.Generic.List' C:..
1:The best overloaded method match for 'SmartRota.ExportHeadWaiter.AddData(int, int, System.Collections.Generic.List)' has some invalid arguments C:..
2:Error 3 'System.Collections.Generic.List' does not contain a definition for 'BackColor' and no extension method 'BackColor' accepting a first argument of type 'System.Collections.Generic.List' could be found (are you missing a using directive or an assembly reference?) C:..
3: Same eroor as above