private void btnNiewR_Click(object sender, EventArgs e) { if (comboBox1.Text == "Credit") { Random rng = new Random(); string rekeningnr = "BE" + rng.Next(99).ToString().PadLeft(2, '0'); for (int i = 1; i <= 3; i++) { int randomnr = rng.Next(9999); rekeningnr += " " + randomnr.ToString().PadLeft(4, '0'); } Random cvn = new Random(); int cv = cvn.Next(999); Rekenings rekenings1 = new Credit(0, "Debit", rekeningnr, cv); rekenings.Add(rekenings1); List <Credit> credit = new List <Credit>(); foreach (var item in rekenings.OfType <Credit>()) { credit.Add(item); } listBoxAccount.DataSource = null; listBoxAccount.DataSource = credit; } else if (comboBox1.Text == "Spaar") { Random rng = new Random(); string rekeningnr = "BE" + rng.Next(99).ToString().PadLeft(2, '0'); for (int i = 1; i <= 3; i++) { int randomnr = rng.Next(9999); rekeningnr += " " + randomnr.ToString().PadLeft(4, '0'); } Rekenings rekenings1 = new Spaar(0, "Spaar", rekeningnr); rekenings.Add(rekenings1); List <Spaar> spaar = new List <Spaar>(); foreach (var item in rekenings.OfType <Spaar>()) { spaar.Add(item); } listBoxAccount.DataSource = null; listBoxAccount.DataSource = spaar; } else if (comboBox1.Text == "Debit") { Random rng = new Random(); string rekeningnr = "BE" + rng.Next(99).ToString().PadLeft(2, '0'); for (int i = 1; i <= 3; i++) { int randomnr = rng.Next(9999); rekeningnr += " " + randomnr.ToString().PadLeft(4, '0'); } Rekenings rekenings1 = new Debit(0, "Debit", rekeningnr); rekenings.Add(rekenings1); List <Debit> debit = new List <Debit>(); foreach (var item in rekenings.OfType <Debit>()) { debit.Add(item); } listBoxAccount.DataSource = null; listBoxAccount.DataSource = debit; } }