Click here to Skip to main content
Rate this: bad
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 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));
                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));
            //    txtTotalAmount.Text = Convert.ToString(double.Parse(txtTotalAmount.Text) - price[5]);
Thanks For your considerations.
Posted 13-Oct-12 7:19am

1 solution

Rate this: bad
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) {
     txtTotalAmount.Text = double.Parse(txtTotalAmount.Text)) + 0.5;
     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.
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)

Advertise | Privacy | Mobile
Web02 | 2.8.150326.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