This is in C# I am trying to figure out the easiest way to get the a single labe
ID: 3758333 • Letter: T
Question
This is in C#
I am trying to figure out the easiest way to get the a single label to change depending on which radio button/checklist option you select. I was thinking about if statements but I would have to create A LOT depending on the different combinations the user can choose from.
Here is the Order Menu video which describes how the label changes depending on the chosen selections. https://www.youtube.com/watch?v=9KJbjca8264&list=PL9QLb2hK-1rIkomX4p3T8Yf02VTXS4sal&index=13. (skim through it to just to see the functionality).
There is a single label on the left had side of the form. that changes depending on what you pick.
Explanation / Answer
******Here is the simplest way***************************
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace PRG16_HOTEL_MENU_listview_
{
public partial class Form1 : Form
{
static int i = 0,total=0;
public Form1()
{
InitializeComponent();
}
private void btn_order_Click(object sender, EventArgs e)
{
int price, quantity;
string item;
price = int.Parse(listView1.SelectedItems[0].SubItems[1].Text);
quantity = int.Parse(txt_quantity.Text);
price = price * quantity;
item = listView1.SelectedItems[0].Text;
listView2.Items.Add(item);
listView2.Items[i].SubItems.Add(price.ToString());
i++;
total = total + price;
lbl_total.Text = total.ToString();
lbl_total.Visible = true;
}
private void btn_orderCancle_Click(object sender, EventArgs e)
{
if (listView2.SelectedItems != null)
{
int deduct=0;
var confirm = MessageBox.Show("Are Sure You Want Cancle Order", "DELETE ORDER", MessageBoxButtons.YesNo, MessageBoxIcon.Warning);
if (confirm == DialogResult.Yes)
{
for (int i = 0; i < listView2.Items.Count; i++)
{
if (listView2.Items[i].Selected)
{
deduct = int.Parse(listView2.Items[i].SubItems[1].Text);
listView2.Items[i].Remove();
i--;
}
}
}
total = total - deduct;
lbl_total.Text=total.ToString();
lbl_total.Visible = true;
}
else
{
MessageBox.Show("Please Select the Item For Cancle order", "Cancle Order", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.