8 Replies - 3056 Views - Last Post: 12 February 2010 - 08:42 AM Rate Topic: -----

#1 cdh  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 37
  • Joined: 19-January 10

[beginner] Question about CheckStateChanged for checkbox

Posted 11 February 2010 - 06:38 PM

I have almost completely finished my app and this is the last step. I'm stuck on this last part. I have some checkboxes that if for some reason the user unchecks or checks one of them after the textbox has displayed the total then the total will clear and require them to recalc order.

Is CheckStateChanged what I'm looking for here? I'd be happy to post my code up but usually when I do that people give me code back. I'd rather read something or learn about it other then just pasting the code you give me. If you can just tell me what I need to research that would be great.

If all else fails I will post up the code.

I tried something along the lines of
if (checkBox1.CheckStateChanged)
{
textBoxTotal.Text = null;
}


But intellisense told me I'm stupid (in so many words) LOL ;)

This post has been edited by cdh: 11 February 2010 - 06:42 PM


Is This A Good Question/Topic? 0
  • +

Replies To: [beginner] Question about CheckStateChanged for checkbox

#2 DuoShin85  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 39
  • View blog
  • Posts: 135
  • Joined: 18-December 09

Re: [beginner] Question about CheckStateChanged for checkbox

Posted 11 February 2010 - 06:54 PM

Do you have any code that depends on the checkbox? If so, can you post some of it? I promise I won't just give you code. :bigsmile:
Was This Post Helpful? 0
  • +
  • -

#3 cdh  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 37
  • Joined: 19-January 10

Re: [beginner] Question about CheckStateChanged for checkbox

Posted 11 February 2010 - 08:18 PM

Here you go. Let me know if you want more.

            if (saladBtn.Checked) //for the salad and addons
            {
                decimal addon = 0.00M;
                decimal salad = 3.50M;

                if (checkBox1.Checked)
                {
                    addon += .25M;
                }
                if (checkBox2.Checked)
                {
                    addon += .25M;
                }
                if (checkBox3.Checked)
                {
                    addon += .25M;
                }
                subTotalBox.Text = string.Format("{0:$0.00}", (salad + addon));
                taxBox.Text = string.Format("{0:$0.00}", ((salad + addon) * tax));
                totalDueBox.Text = string.Format("{0:$0.00}", ((salad + addon) * tax) + (salad + addon));

            }

            
        }

        private void burgerBtn_CheckedChanged(object sender, EventArgs e) //changes checkbox text display based upon radiobutton selection
        {
            if (burgerBtn.Checked)
            {
                checkBox1.Text = "Lettuce, tomato and onion";
                checkBox2.Text = "Mayo and mustard";
                checkBox3.Text = "French fries";
                groupBox2.Text = "Addon Items $0.75 each";
            }
            else
            {
                checkBox1.Checked = false;
                checkBox2.Checked = false;
                checkBox3.Checked = false;
                subTotalBox.Text = null;
                taxBox.Text = null;
                totalDueBox.Text = null;
            }
        }

Was This Post Helpful? 0
  • +
  • -

#4 DuoShin85  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 39
  • View blog
  • Posts: 135
  • Joined: 18-December 09

Re: [beginner] Question about CheckStateChanged for checkbox

Posted 11 February 2010 - 09:08 PM

It looks like you're resetting the textboxes when the burger button is unchecked. Is that what you want to do?
Was This Post Helpful? 0
  • +
  • -

#5 cdh  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 37
  • Joined: 19-January 10

Re: [beginner] Question about CheckStateChanged for checkbox

Posted 11 February 2010 - 09:19 PM

Yes it is. There is 2 other radio buttons so if you select one of them it should reset the checkboxes.

Now I need to do the other part I referenced in the first post.

Thanks
Was This Post Helpful? 0
  • +
  • -

#6 DuoShin85  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 39
  • View blog
  • Posts: 135
  • Joined: 18-December 09

Re: [beginner] Question about CheckStateChanged for checkbox

Posted 11 February 2010 - 09:29 PM

You should be able to call the CheckChanged event for the checkboxes to clear the textboxes.

Something like the following:
private void checkBox_CheckChanged(object sender, EventArgs e)
{
    //Do whatever you want here.
}


Was This Post Helpful? 0
  • +
  • -

#7 Hwang Sung Wook  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 30
  • Joined: 04-February 10

Re: [beginner] Question about CheckStateChanged for checkbox

Posted 11 February 2010 - 10:10 PM

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 SearchWebsitdIDs
{


    public partial class TestForm : Form
    {
        public TestForm()
        {
            InitializeComponent();
        }
        int count = 0 ;
        decimal tax = 12.5M;
        decimal addon = 0.0M;
        decimal salad = 3.5M ;


        private void TestForm_Load(object sender, EventArgs e)
        {
            
   
    }

        private void btnShow_Click(object sender, EventArgs e)
        {
            if (count == 0)
            {
                MessageBox.Show("check the checkbox first.");

            }
            else
            {

                subTotalbox.Text = string.Format("salad + addon : ${0}", salad + addon);
                texBox.Text = string.Format("salad + addon * tax : ${0}", (salad + addon) * tax);
                totalDue.Text = string.Format("Total : ${0}", ((salad + addon) * tax) + (salad + addon));


            }
        }

        private void ckapple_CheckedChanged(object sender, EventArgs e)
        {
            if(ckapple.Checked == true) {
            addon +=0.25M;
                count+=1;
            }
            else if (ckapple.Checked == false) {
            

                if(addon < 0) {
                addon = 0.00M;
                count-=1;
                }
                else {
            addon -= 0.25M;
                count-=1;
                
                }
                
                }
        
        }

        private void ckStraw_CheckedChanged(object sender, EventArgs e)
        {
        
            if(ckStraw.Checked == true) {
            addon +=0.25M;
            }
            else if (ckStraw.Checked == false) {
            

                if(addon < 0) {
                addon = 0.00M;
                }
                else {
            addon -= 0.25M;
                }
                
                }
        }

        private void ckJuice_CheckedChanged(object sender, EventArgs e)
        {
            
            if(ckJuice.Checked == true) {
          addon +=0.25M;
            }
            else if (ckJuice.Checked == false) {
            

                if(addon < 0) {
                addon = 0;
                    addon -=0.00M;
                }
                else {
            addon -= 0.25M;
                }
                
                
        }



        }


    }




i am not live a america, so you execute this form, try write different value : tax value.
Was This Post Helpful? 0
  • +
  • -

#8 cdh  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 37
  • Joined: 19-January 10

Re: [beginner] Question about CheckStateChanged for checkbox

Posted 11 February 2010 - 11:42 PM

Thank you. I finished it! This is the first program I wrote which didn't reference any reading material that we have read since I began. I guess this was a challenge app to see if we could build it. As frustrating as it was to have to use things I have never read about, code I never saw or read about, it's feel good to know I got it working correctly.
Was This Post Helpful? 0
  • +
  • -

#9 DuoShin85  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 39
  • View blog
  • Posts: 135
  • Joined: 18-December 09

Re: [beginner] Question about CheckStateChanged for checkbox

Posted 12 February 2010 - 08:42 AM

I'm glad you finished your program. Congratulations!
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1