private void solveGrid_Click(object sender, EventArgs e) { SudokuSolver sudokuSolver = new SudokuSolver(); var cellArray = this.Controls.OfType <MyCellBox>().ToList(); int[,] intSudokuGrid = new int[9, 9]; for (int row = 0; row < 9; row++) { for (int column = 0; column < 9; column++) { if (sudokuSolver.isDigit(cellArray[row * 9 + column].Text)) { intSudokuGrid[row, column] = int.Parse(cellArray[row * 9 + column].Text); } //intSudokuGrid[row, column] = int.Parse(cellArray[row * 9 + column].Text); } } SudokuGrid mySudoku = new SudokuGrid(); mySudoku = sudokuSolver.FromIntArray(intSudokuGrid); if (mySudoku.IsSolved()) { infoBox.Text = "the sudoku inputted is already solved"; } else if (mySudoku.IsValid()) { sudokuSolver.Solve(mySudoku, true); for (int i = 0; i < cellArray.Count; i++) { cellArray[i].Text = "" + mySudoku[i / 9, i % 9].ToStringVal(); } } else { infoBox.Text = "the sudoku inputted was invalid"; } }