void MainFormLoad(object sender, EventArgs e) { LoadData(); //on product selected lstProductList.SelectedValueChanged += delegate { Product product = lstProductList.SelectedItem as Product; txtOpeningStock.Text = (product.Stock).ToString(); txtQty.Text = product.Stock.ToString(); txtProductName.Text = product.Name; }; //on add button clicked btnAdd.Click += delegate { string productName = txtProductName.Text.Trim().ToUpper(); int totalStock = 0; int.TryParse(txtOpeningStock.Text, out totalStock); Product product = new Product(productName, totalStock); _stockManager.AddProduct(product); }; }