Solved

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

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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

For those of you who don't follow the news, or just happen to live under rocks, Microsoft Research released a beta SDK (http://www.microsoft.com/en-us/download/details.aspx?id=27876) for the Xbox 360 Kinect. If you don't know what a Kinect is (http:…
Wouldn’t it be nice if you could test whether an element is contained in an array by using a Contains method just like the one available on List objects? Wouldn’t it be good if you could write code like this? (CODE) In .NET 3.5, this is possible…
This video Micro Tutorial shows how to password-protect PDF files with free software. Many software products can do this, such as Adobe Acrobat (but not Adobe Reader), Nuance PaperPort, and Nuance Power PDF, but they are not free products. This vide…
There are cases when e.g. an IT administrator wants to have full access and view into selected mailboxes on Exchange server, directly from his own email account in Outlook or Outlook Web Access. This proves useful when for example administrator want…

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