[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Check if any five textboxes have changed

Posted on 2007-10-09
11
Medium Priority
?
255 Views
Last Modified: 2010-04-15
Five user editable textboxes...
TextBoxName, TextBoxTitle, TextBoxDirectLine, TextBoxExtensionNumber, and TextBoxMobile.

Would like to know how without writing ridiculously long if then sequences can I check whether any one or more of the boxes have changed content and if so to display an error.

The original content is changed to strings called name, title, directline, extensionnumber, and mobile (respectively). This is what i compare the textbox content to when clicking a button.

Cheers in advance...
0
Comment
Question by:Antonio King
  • 4
  • 3
  • 2
  • +1
11 Comments
 
LVL 11

Accepted Solution

by:
udhayakumard earned 800 total points
ID: 20039262
Use TextChanged event of the textbox
0
 

Author Comment

by:Antonio King
ID: 20039281
"Would like to know how without writing ridiculously long if then sequences can I check whether any one or more of the boxes have changed content and if so to display an error."
0
 
LVL 4

Assisted Solution

by:jimstar
jimstar earned 800 total points
ID: 20039305
A few ways to do this:

1. Use TextChanged event handler as udhayakumard mentioned, and when you detect a change either set a flag (for later use in your button handler), or immediately restore the old value / throw a message up.

2. On your button handler, use if/then statements to detect a change after the fact.

3. Disable the editable property to prevent change to the data.

4. Ignore the data in the text boxes (if that is an option for you) and in your button handler just use the old values. This might not work, as I don't know what your situation / usage is.

Aside from those options, I don't know what else you could do.
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
LVL 29

Expert Comment

by:Gautham Janardhan
ID: 20039308
textEdit1.TextChanged += new EventHandler(Changed);
                  textEdit2.TextChanged += new EventHandler(Changed);
                  textEdit3.TextChanged += new EventHandler(Changed);
                  textEdit4.TextChanged += new EventHandler(Changed);


private void Changed(object sender, EventArgs e)
            {
                  ((Control)sender).Tag = "1";
            }


to check

for(int i=0;i<this.Controls.Count;i++)
                  {
                        if(this.Controls[i].Tag == "1")
                        {
                              // do what u want;
                        }
                  }
0
 

Author Comment

by:Antonio King
ID: 20039316
I like the sound of setting a flag, but i'm unfamiliar with how to do this?
0
 
LVL 29

Expert Comment

by:Gautham Janardhan
ID: 20039324
just point all change to one event

delcare a bool variable in the form (i used the controls tag itself so i can identify the control )

and on change set Falg = true;

and at the end where u want to check check this flag
if(Flag)
{
 // do
}
0
 
LVL 4

Assisted Solution

by:jimstar
jimstar earned 800 total points
ID: 20039412
>> I like the sound of setting a flag

The basic idea is that you add an event handler to each textbox for the TextChanged event. Elsewhere, you declare a boolean value (say bChanged). Then, whenever the TextChanged event is called for one of the textboxes, you set bChanged = true. Later, when the user clicks the button, you just check bChanged, and if it is true, you know they changed one of the textboxes.
0
 
LVL 11

Assisted Solution

by:udhayakumard
udhayakumard earned 800 total points
ID: 20039555
declare this globally

bool changed = false;

                  textEdit1.TextChanged += new EventHandler(Changed);
                  textEdit2.TextChanged += new EventHandler(Changed);
                  textEdit3.TextChanged += new EventHandler(Changed);
                  textEdit4.TextChanged += new EventHandler(Changed);

private void Changed(object sender, EventArgs e)
{
           changed = true;
}


finally somewhere to check the status:

if(changed)
     MessageBox.Show("Text changed");
else
     MessageBox.Show("Text not changed");

0
 

Author Comment

by:Antonio King
ID: 20039594
how do i declare changed globally?
0
 
LVL 29

Assisted Solution

by:Gautham Janardhan
Gautham Janardhan earned 400 total points
ID: 20039650
where u declare the form items

just add this line after that

bool changed = false;
0
 

Author Comment

by:Antonio King
ID: 20039798
Combination of three of you helped me solve this.

Many thanks all that helped :)
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
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…
Are you ready to place your question in front of subject-matter experts for more timely responses? With the release of Priority Question, Premium Members, Team Accounts and Qualified Experts can now identify the emergent level of their issue, signal…
In a question here at Experts Exchange (https://www.experts-exchange.com/questions/29062564/Adobe-acrobat-reader-DC.html), a member asked how to create a signature in Adobe Acrobat Reader DC (the free Reader product, not the paid, full Acrobat produ…
Suggested Courses

826 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