Solved

Given the following diagram if one of the controls change enable save button.

Posted on 2008-06-13
5
166 Views
Last Modified: 2013-12-17
How can I enable save button if one of the controls changes. See attached file.

enablesavebutton.jpg
0
Comment
Question by:mathieu_cupryk
  • 3
  • 2
5 Comments
 
LVL 11

Accepted Solution

by:
Babycorn-Starfish earned 500 total points
Comment Utility
Hi, this is pretty crude, but works. If it works for you i can tidy it up to make it less dependent on hard coded variables.

Basically for each control that can change you assign it the same event handler, in the event handler you check that the sender of the event has Focus. We check it has focus to stop us processing the event twice for the radio buttons as when we click on a different radio button the checked state changes in the current selection in addition to the newly selected one, not really a problem given that you are enabling a save button.

Anyway, hope this helps
public partial class Form1 : Form

    {

        private bool onLoad = true;

        public Form1()

        {

            InitializeComponent();

        }
 

        private void Form1_Load(object sender, EventArgs e)

        {

            radioButton1.CheckedChanged += new EventHandler(CheckedChanged);

            radioButton2.CheckedChanged += new EventHandler(CheckedChanged);

            radioButton3.CheckedChanged += new EventHandler(CheckedChanged);
 

            checkBox1.CheckedChanged += new EventHandler(CheckedChanged);

            checkBox2.CheckedChanged += new EventHandler(CheckedChanged);

            checkBox3.CheckedChanged += new EventHandler(CheckedChanged); 

        }
 

        protected override void OnActivated(EventArgs e)

        {

            onLoad = false;

        }
 

        void CheckedChanged(object sender, EventArgs e)

        {

            if (!onLoad)

            {

                Control c = (Control)sender; 

                if(c.Focused)

                {

                    MessageBox.Show("Changed");

                }

            }  

        }

    }

Open in new window

0
 

Author Comment

by:mathieu_cupryk
Comment Utility
I got something like this:
 private bool onLoad = true;

        public Form1()
        {
            InitializeComponent();
            BuildStatBar();
            EnableSaveButton();
        }

        private void EnableSaveButton()
        {
            rbtnInitialPriceOption.CheckedChanged += new EventHandler(CheckedChanged);
            rbtnAdjustmentPriceOption.CheckedChanged += new EventHandler(CheckedChanged);
            rbtnInterimPaymentOption.CheckedChanged += new EventHandler(CheckedChanged);
            rbtnFinalPaymentOption.CheckedChanged += new EventHandler(CheckedChanged);

            chkboxBarley.CheckedChanged += new EventHandler(CheckedChanged);
            chkboxDesBarley.CheckedChanged += new EventHandler(CheckedChanged);
            chkboxDurum.CheckedChanged += new EventHandler(CheckedChanged);
            chkboxWheat.CheckedChanged += new EventHandler(CheckedChanged);
     
        }

        protected override void OnActivated(EventArgs e)
        {
            onLoad = false;
        }

        private void CheckedChanged(object sender, EventArgs e)
        {
            if (!onLoad)
            {
                Control c = (Control)sender;
                if (c.Focused)
                {
                    MessageBox.Show("Changed");
                }
            }
        }

I have not tested it yet but we need to check if the person the txtListName has changed?

0
 

Author Comment

by:mathieu_cupryk
Comment Utility
private void Form1_Load(object sender, EventArgs e)
        {
            sbPnlMsg.Text = "";
            LoadInitialPriceReporting();
            BuildStatBar();
            HideTabs();
            EnableSaveButton();
        }

        private void EnableSaveButton()
        {
            rbtnInitialPriceOption.CheckedChanged += new EventHandler(CheckedChanged);
            rbtnAdjustmentPriceOption.CheckedChanged += new EventHandler(CheckedChanged);
            rbtnInterimPaymentOption.CheckedChanged += new EventHandler(CheckedChanged);
            rbtnFinalPaymentOption.CheckedChanged += new EventHandler(CheckedChanged);

            chkboxBarley.CheckedChanged += new EventHandler(CheckedChanged);
            chkboxDesBarley.CheckedChanged += new EventHandler(CheckedChanged);
            chkboxDurum.CheckedChanged += new EventHandler(CheckedChanged);
            chkboxWheat.CheckedChanged += new EventHandler(CheckedChanged);
     
        }
0
 
LVL 11

Expert Comment

by:Babycorn-Starfish
Comment Utility
Hi,

for the textbox you use the textchanged event:

textBox1.TextChanged += new EventHandler(CheckedChanged);

0
 

Author Comment

by:mathieu_cupryk
Comment Utility
cool.
0

Featured Post

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

Suggested Solutions

The ECB site provides FX rates for major currencies since its inception in 1999 in the form of an XML feed. The files have the following format (reducted for brevity) (CODE) There are three files available HERE (http://www.ecb.europa.eu/stats/exch…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…

728 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now