Solved

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

Posted on 2008-06-13
5
172 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

Resolve Critical IT Incidents Fast

If your data, services or processes become compromised, your organization can suffer damage in just minutes and how fast you communicate during a major IT incident is everything. Learn how to immediately identify incidents & best practices to resolve them quickly and effectively.

Question has a verified solution.

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

Welcome my friends to the second instalment and follow-up to our Minify and Concatenate Your Scripts and Stylesheets (http://www.experts-exchange.com/Programming/Languages/.NET/ASP.NET/A_4334-Minify-and-Concatenate-Your-Scripts-and-Stylesheets.html)…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

856 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