Solved

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

Posted on 2008-06-13
5
169 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
ID: 21784675
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
ID: 21786159
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
ID: 21786166
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
ID: 21786321
Hi,

for the textbox you use the textchanged event:

textBox1.TextChanged += new EventHandler(CheckedChanged);

0
 

Author Comment

by:mathieu_cupryk
ID: 21786420
cool.
0

Featured Post

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Creating an analog clock UserControl seems fairly straight forward.  It is, after all, essentially just a circle with several lines in it!  Two common approaches for rendering an analog clock typically involve either manually calculating points with…
This article shows how to deploy dynamic backgrounds to computers depending on the aspect ratio of display
This Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

816 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

8 Experts available now in Live!

Get 1:1 Help Now