List View Application using C#
Program:
using System;
usingSystem.Collections.Generic;
usingSystem.ComponentModel;
usingSystem.Data;
usingSystem.Drawing;
usingSystem.Linq;
usingSystem.Text;
usingSystem.Threading.Tasks;
using System.Windows.Forms;
namespace WindowsFormsApplication3
{
Public partial class Form1: Form
{
int total = 0;
public Form1()
{
InitializeComponent();
}
Private void Form1_Load (object sender, EventArgs e)
{
listView1.View = View.Details;
listView1.GridLines = true;
listView1.FullRowSelect=true;
listView1.HideSelection = false;
listView1.Columns.Add("ITEM",100);
listView1.Columns.Add("PRICE",70);
listView2.View = View.Details;
listView2.GridLines = true;
listView2.FullRowSelect = true;
listView2.HideSelection = false;
listView2.Columns.Add("ITEM", 100);
listView2.Columns.Add("PRICE", 70);
ListViewItem item1 = newListViewItem("PIZZA",0);
item1.SubItems.Add("70");
listView1.Items.Add(item1);
ListViewItem item2 = newListViewItem(" SANDWICH", 1);
item2.SubItems.Add("60");
listView1.Items.Add(item2);
item3.SubItems.Add("75");
listView1.Items.Add(item3);
ListViewItem item4 = newListViewItem("COLDDRINK", 3);
item4.SubItems.Add("25");
listView1.Items.Add(item4);
textBox1.Text = "1";
}
Private
void btncancel_Click (object sender, EventArgs e)
{
textBox1.Text = "1";
}
Private
void btninsert_Click (object sender, EventArgs e)
{
if (listView1.SelectedItems.Count > 0)
{
intoldprice = 0, newprice = 0, quantity = 0;
quantity = Convert.ToInt32(textBox1.Text);
oldprice
= Convert.ToInt32(listView1.SelectedItems[0].SubItems[1].Text);
newprice
= oldprice * quantity;
total
= total + newprice;
label3.Text = total.ToString();
ListViewItemitemcopy = newListViewItem(listView1.SelectedItems[0].Text);
itemcopy.SubItems.Add(newprice.ToString());
listView2.Items.Add(itemcopy);
}
else
{
MessageBox.Show("Please Select atleast One
Item");
}
}
Private
void btncancelorder_Click (object sender, EventArgs e)
{
if (listView2.SelectedItems.Count > 0)
{
intnewprice = 0;
newprice=Convert.ToInt32(listView2.SelectedItems[0].SubItems[1].Text);
total = total - newprice;
label3.Text=total.ToString();
listView2.Items.Remove(listView2.SelectedItems[0]);
}
else
{
MessageBox.Show("Please Select atleast One
Item");
}
}
}
}
No comments:
Post a Comment