473,383 Members | 1,735 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,383 software developers and data experts.

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 35829
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Jeroen van vliet | last post by:
Hello How can i run a query from a mdb database and show it in a datagrid control when i put in a letter in a textbox? for instance. when i type the letter "A" in the textbox i want to run a...
2
by: Hareth | last post by:
i got the idea "form.textbox.text = label.text" from vb... i tried it in C# but it generated errors i found a diff example from :...
2
by: Alpha | last post by:
Hi, I have a window based program. One of the form has several textboxes and a datagrid. The textboxes are bind to the same dataset table as the datagrid and the text changes to reflect different...
5
by: Steve S | last post by:
Heres what I want to do...User types into a texbox, clicks a button, the button saves that text to a file. The problem is that when I click the submit button, any changes made to the textbox are...
2
by: jason | last post by:
hello. i am just trying to save a TextBox.Text value to a database, but strangely, when the value is changed on the web form, the changes are not recognized in the event where i try to save the...
3
by: RipperT | last post by:
Hello, I am using VB2005. I would like to check a textbox to see if it is blank using a Try Catch block. I assumed an easy way to do that would be to perform some action on the string that can't...
2
by: Dan Sikorsky | last post by:
How can we tell if the value in a FormView EditItemTemplate TextBox has changed from its initial value so that we know if we have to update the corresponding db table column value? -- Thank you...
0
by: jvb | last post by:
Hey all, quick question I have a form with 6 tabs on it. On each tab there is a textbox which is bound to a specific column in a dataset. When I load the form, I bind all the controls, however,...
3
nev
by: nev | last post by:
my textbox displays "hello" i change the value of textbox through code like this: textbox.text = "" then i do: bindingsource.endedit() tableadapter.update(dataset.datatable)
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.