private void btn1_addItem_Click(object sender, EventArgs e) { try { //Adding a new item to the data grid view Product item = new Product(); item.prodID = textBox1_ID.Text; item.title = textBox2_title.Text; item.genre = textBox3_genre.Text; item.releaseDate = textBox4_releaseDate.Text; item.price = double.Parse(textBox5_price.Text); item.stockQnty = int.Parse(textBox6_stockQnty.Text); IM.addItem(item); dataGridView_inventory.DataSource = IM.getItemList(); //Writing to file StreamWriter outFile = new StreamWriter("inventoryTextFile.txt", true); for (int i = 0; i < 1; i++) { outFile.WriteLine(item.prodID + ", " + item.title + ", " + item.genre + ", " + item.releaseDate + ", " + item.price + ", " + item.stockQnty); } outFile.Flush(); outFile.Close(); //Text boxes are ready for user to type more info into them textBox1_ID.Text = ""; textBox2_title.Text = ""; textBox3_genre.Text = ""; textBox4_releaseDate.Text = ""; textBox5_price.Text = ""; textBox6_stockQnty.Text = ""; } catch(Exception ex) { MessageBox.Show("Please make sure you fill out the text boxes with the appropriate information."); } }