Click here to Skip to main content
11,636,598 members (73,969 online)
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C#
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)
        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 13-Oct-12 6:19am
FoxRoot989

1 solution

Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

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

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.
  Permalink  
Comments
TuranEmre at 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)

  Print Answers RSS
0 jyo.net 263
1 Sergey Alexandrovich Kryukov 254
2 stibee 249
3 Suvendu Shekhar Giri 225
4 OriginalGriff 183
0 OriginalGriff 8,941
1 Sergey Alexandrovich Kryukov 8,459
2 Mika Wendelius 6,849
3 F-ES Sitecore 2,364
4 Suvendu Shekhar Giri 2,320


Advertise | Privacy | Mobile
Web03 | 2.8.150728.1 | Last Updated 14 Oct 2012
Copyright © CodeProject, 1999-2015
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100