Do I just create snippet that looks like this?
private void Update_DataChanged(object sender, EventArgs e)
{
}
Main Topics
Browse All TopicsHi Guys,
I have a textbox control on my screen. I want to call a method when the content of that textbox has changed. I know I can doubleclick on the event "TextChanged" on the textbox then it takes me into code, however I would rather simply paste my method into the events box.
Right now if I click on the dropdown arrow next to the "TextChanged" property it only allows me to choose methods that the app produced for me such as form1_load() etc.
The reason I want to do this, is because I have like 30 text fields on the screen and I need to set them all to change a bool variable that data has changed so that when the user leaves or attempts to leave the screen it will warn them to save first.
Any suggestions?
Thanks!
This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.
Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.
If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.
Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.
Access the answers to your technology questions today.
30-day free trial. Register in 60 seconds.
Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Try it out and discover for yourself.
30-day free trial. Register in 60 seconds.
Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.
So in the method I create - it appears I can't just create a:
private void Update_DataChanged()
{
DataChanged = true;
}
I actually need to make it -
private void Update_DataChanged(object sender, EventArgs e)
{
DataChanged = true;
}
What does having the object sender, EventArgs e do that makes it available as a selection in the event list?
Instead of "double clicking" on the TextBox objects, I suggest doing this manually, as it is one of those times that manual is better. I never use the GUI design in VS (except when time is absolutely pressing), and I don't suggest you use it, either. However, just create one method, name it something meaningful, and place in its body whatever you want to happen when a TextBox control's text is changed. Make it return void, and take an Object and EventArgs as a parameter. Just make one method for this. You do NOT need 30. I've seen people implement the exactly same method multiple times too much for my own good.
The method should look like the one in the following code snippet, obviously with your code in the body and the name of your choice.
When you've done this, you can use the designer and just copy the name of your method, go to each TextBox on your form, and paste the method's name in the TextChanged event property. Done and done. I wouldn't do it this way, but hey, whatever works for you. Make sure to put this method in the class definition of the Form the TextBox controls reside on, though.
Hope it helps,
Nate
If it's always the same method... have them all relate to the same delegate handler method, then have that method tell yours to execute. Not just accomplished by the designer, you will have to go into your designer code and modify it yourself, or add the events outside of the designer in the other code window for VS Windows Forms layouts. Simply put, like the following. (is not full code but the gist of the idea)
>> What does having the object sender, EventArgs e do that makes it available as a selection in the event list?
Sorry, when I posted I didn't see any responses yet.
The signature you're referring to is the default signature for event-handling methods (not all methods, of course...). The "sender" object is (according to .NET standards) the object that fired the event. It provides a way to detect what fired the event without having separate methods for each and every object that may trigger the same code.
The second parameter, EventArgs, is an object that derives from the "EventArgs" class (or an instance of the EventArgs class itself). Meaningful data may or may not be passed, completely dependent on the event that was triggered. For example, a MouseClick event takes a MouseEventArgs parameter instead of EventArgs. The MouseEventArgs, which derives from EventArgs, holds data correpsonding to where the mouse was when it was clicked, which button(s) were clicked, etc. For methods that don't need this kind of data about their event, EventArgs.Empty is usually passed (again, according to .NET standard), instead of just null.
Sounds like your coming from the old VB style where the function name directly tied to the event handler. In C# you "subscribe" your event handler function to the events of the particular control. A control can therefore send the event to 0 or more handlers. As long as the parameters of the handler function match what the control event can send out your set! name is arbitrary.
An example of something I just did : i have a label that when compiled under debugging acts like a button (toggles some behind the scenes attributes for testing) As you see a single or double click both activate the same event handler function.
Double click on the FIRST TextBox so you get the stub and add the code in there:
private bool DataChanged = false;
private void textBox1_TextChanged(objec
{
DataChanged = true;
}
Now go back to the Form design view and select all the rest of the TextBoxes. Click on the Lightning bolt to get the events. Find the TextChanged() event, click on the dropdown, and select "textBox1_TextChanged".
Now all of the TextBoxes will cause that same method to fire and thus toggle DataChanged to true.
Business Accounts
Answer for Membership
by: ProWebNetworksPosted on 2009-11-04 at 07:44:50ID: 25740449
This is a windows app by the way...sorry.