I am using c# to try and populate a datagridview with random numbers but for some reason I keep getting the same value in all the cells.
public int GenerateRandomNumber()
{
const int minimumNumber = -9;
const int maximumNumber = 15;
var random = new Random();
var randomNumber = random.Next(minimumNumber, maximumNumber);
return randomNumber;
}
gameBoard is the datagrid view.
private void populateButton_Click(object sender, EventArgs e)
{
CreateGameBoard((int)columnsNumericUpDown.Value,(int)rowsNumericUpDown.Value);
gameBoard.RowTemplate.Height = gameBoard.Height/gameBoard.RowCount;
foreach (DataGridViewRow row in gameBoard.Rows)
{
foreach (DataGridViewCell cell in row.Cells)
{
cell.Value = GenerateRandomNumber();
}
}
}