469,361 Members | 2,310 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,361 developers. It's quick & easy.

How to check if textbox text changed?

Besides using a very long if statement and storing old text box values,
is there a way to see if text box values have changed since an event?

For example, say I have 8 textboxes when the form loads. They start
empty. The user types values into 2 of them and clicks search. Before
running the search, I want to make sure I don't waste cpu cycles
because perhaps the user didn't change any values, which means I don't
need to run the search. I can use results already in memory.

Thanks,
Brett

Jan 12 '06 #1
4 34534
Brett,

I would create a control that extends TextBox. In this control, I would
have a reset point which would indicate whether or not the text has changed
from the last reset point.

Then, what you can do is you can set the reset point. When it is set in
your control, you would store the text of the string somewhere in your
control. When you check to see if the control is "dirty", you would then
check the current text against the stored text. If they are different, then
they are dirty.

Of course, this only works if the data source you are comparing against
can be guaranteed to not have changed. The filters could still be the same,
but the data might not be, and the results, different.

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Brett Romero" <ac*****@cygen.com> wrote in message
news:11**********************@g43g2000cwa.googlegr oups.com...
Besides using a very long if statement and storing old text box values,
is there a way to see if text box values have changed since an event?

For example, say I have 8 textboxes when the form loads. They start
empty. The user types values into 2 of them and clicks search. Before
running the search, I want to make sure I don't waste cpu cycles
because perhaps the user didn't change any values, which means I don't
need to run the search. I can use results already in memory.

Thanks,
Brett

Jan 12 '06 #2
Handle the TextChanged Event of the TextBox, by setting a boolean value
indicating that the text has changed.

--
HTH,

Kevin Spencer
Microsoft MVP
..Net Developer
You can lead a fish to a bicycle,
but it takes a very long time,
and the bicycle has to *want* to change.

"Brett Romero" <ac*****@cygen.com> wrote in message
news:11**********************@g43g2000cwa.googlegr oups.com...
Besides using a very long if statement and storing old text box values,
is there a way to see if text box values have changed since an event?

For example, say I have 8 textboxes when the form loads. They start
empty. The user types values into 2 of them and clicks search. Before
running the search, I want to make sure I don't waste cpu cycles
because perhaps the user didn't change any values, which means I don't
need to run the search. I can use results already in memory.

Thanks,
Brett

Jan 12 '06 #3
Hi,
As kevin says, add an eventhandler to TextChanged and trap the change in
a bool for later examination.
---------- snip
private bool boxChanged = false;
.......
this.textBoxTest.TextChanged += new
System.EventHandler(this.textBoxTest_TextChanged);
.......
private void textBoxTest_TextChanged(object sender, System.EventArgs
e)
{
this.boxChanged = true;
}
---------- snop
HTH
Mark
Jan 12 '06 #4
Or you can just test the textBox1.Modified to see if it's true.
"Mark Carew" <ma*******@magicwanddept.com.au> wrote in message
news:On**************@TK2MSFTNGP14.phx.gbl...
Hi,
As kevin says, add an eventhandler to TextChanged and trap the change
in a bool for later examination.
---------- snip
private bool boxChanged = false;
.......
this.textBoxTest.TextChanged += new
System.EventHandler(this.textBoxTest_TextChanged);
.......
private void textBoxTest_TextChanged(object sender, System.EventArgs
e)
{
this.boxChanged = true;
}
---------- snop
HTH
Mark

Jan 12 '06 #5

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

2 posts views Thread by Jeroen van vliet | last post: by
2 posts views Thread by Hareth | last post: by
5 posts views Thread by Steve S | last post: by
3 posts views Thread by RipperT | last post: by
1 post views Thread by CARIGAR | last post: by
reply views Thread by zhoujie | last post: by
1 post views Thread by Marylou17 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.