Using WinForm C# I'm trying to set a the number of rows in the dataGridView to match the numericUpDown default value of 4 and then have the number of rows increase/decrease in line with the numericUpDown value.
I'm quite new to this and so far I've tried the following:
private void numericUpDown1_ValueChanged(object sender, EventArgs e)
{
while (dataGridView1.Rows.Count < numericUpDown1.Value) ;
dataGridView1.Rows.Add();
while (dataGridView1.Rows.Count > numericUpDown1.Value) ;
dataGridView1.Rows.Remove();
}
It seems to work in terms of adding a new row when the numericUpDown value is increased but then errors when I try to decrease.