Shopping Cart Visual Program in C Sharp – This is a Windows forms application in C Sharp. Design a Shopping cart using List box to ass items with prices. Add a text box to enter new items (add cart) in list box 1. Add three buttons , first button ‘Add Item to Cart’ will add item in text box to list box 1. The second button is ‘Remove selected Item from Cart list box 1. The third button is to ‘Display Selected Items from Cart – List box 1 into another list box 2.
Source Code of List Box Shopping Cart
using System; using System.Windows.Forms; namespace ListBoxShoppingCart { public partial class Form1 : Form { public Form1() { InitializeComponent(); } private void listBox1_SelectedIndexChanged(object sender, EventArgs e) { } private void button3_Click(object sender, EventArgs e) { foreach (string sitem in listBox1.SelectedItems) { listBox2.Items.Add(sitem); } } private void button1_Click(object sender, EventArgs e) { listBox1.Items.Add(textBox1.Text); } private void button2_Click(object sender, EventArgs e) { listBox1.Items.Remove(listBox1.Text); } private void button4_Click(object sender, EventArgs e) { listBox2.Items.Clear(); } } }
Output