Click here to Skip to main content
15,843,591 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hello everyone,

I am trying to develop an Pizza Ordering System. I am confused about using Checked List Boxes. I have a checked list box and 5 items. The software is expected to do this; when user clicked an item1, the total prize should increse + 0.5 when item1 is unclicked then the total prize should return the actual value. and so on.

totalprize = 10;
item1 checked = 10.50
item1 is unchecked = 10.00
item2 is checked = 10.75
item2 is unchecked = 10.00
both item1 and item2 is checked = 11.25 and so on.

I want help about the property of checked list box and logic (the if else structure) of this part.

Snapshot:
Snapshot Of Program[^]

Code I am confused:(Completely Wrong, not calculating)
C#
private void checkedListBoxAdditions_ItemCheck(object sender, ItemCheckEventArgs e)
{
    if (checkedListBoxAdditions.GetItemChecked(checkedListBoxAdditions.SelectedIndex))
    {
        txtTotalAmount.Text = Convert.ToString(price[4] + double.Parse(txtTotalAmount.Text));
    }
    else
    {
        txtTotalAmount.Text = Convert.ToString( double.Parse(txtTotalAmount.Text) - price[4] );
    }
    //if (checkedListBoxAdditions.GetItemChecked(checkedListBoxAdditions.Items.IndexOf("Domato")))
    //{
    //    txtTotalAmount.Text = Convert.ToString(price[5] + double.Parse(txtTotalAmount.Text));
    //}
    //else
    //{
    //    txtTotalAmount.Text = Convert.ToString(double.Parse(txtTotalAmount.Text) - price[5]);
    //}
}


Thanks For your considerations.
T.E
Posted

1 solution

Instead of using CheckedListBox, you could have used 5 checkboxes and that would have made your life easier. See below -

Add 5 checkboxes say c1,c2,c3,c4,c5 and add event handlers for CheckedCHanged Event

C#
private void c1_CheckedChanged(Object sender, EventArgs e) {
   if(c1.Checked)  
     txtTotalAmount.Text = double.Parse(txtTotalAmount.Text)) + 0.5;
   else
     txtTotalAmount.Text = double.Parse(txtTotalAmount.Text)) - 0.5;
}


Change the amount you want to add/subtract in each checkbox event and this solves what you are looking for.
 
Share this answer
 
Comments
FoxRoot 21-Oct-12 10:42am    
Thanks Nitesh but I should use a CheckedListBox.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900