Solved

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

Posted on 2008-06-13
5
174 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Get sourcecode path 14 47
Header Font Size in Grid View 6 27
VB.net Is there code behind PowerPivot 2 51
PowerShell: ForEach-Object Export to CSV 4 46
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)…
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…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the admini…

726 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