Click here to Skip to main content
15,891,248 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have 2 forms and i am dynamically creating textboxes on the second form. i want to know if the text in any of those boxes were changed so that i can change it in the XML file it writes the textbox text to.
Update:
I understand how to create and get the text from the dynamically created textboxes.It is figuring out which one was changed and then changing it in the XML file that i cant figure out.

What I have tried:

i tried using a foreach statement but wasnt sure how to find which one was changed
Posted
Updated 7-Aug-18 10:09am
v2

var totalTextBox = 5;

// Create TextBox dynamically
for ( int i = 0 ; i < totalTextBox ; i++ )
{
   TextBox tb = new TextBox();
   tb.ID = "tb" + i;
   tb.TextChanged += TextBox_TextChanged;
}

// All TextBox point to same event
private void TextBox_TextChanged(object sender, EventArgs e)
{
   // sender points to modified TextBox
   // All you need to do is cast it
   TextBox modified = (TextBox)sender;
}
 
Share this answer
 
Comments
Codingnow20 7-Aug-18 13:37pm    
Is there a property of text box that I'm missing?? Textbox.ID doesn't show as an option
Codingnow20 7-Aug-18 16:09pm    
This helped me think thru the problem better Thanks
I presume that you would override the .Change event on the textboxes? Which language are we talking about? Presuming C#, you would create an eventhandler for it, like this:

this.textbox.change += new EventHandler (myFunctionName);


Then later in your code:

void myFunctionName(object Sender, EventArgs e) { do something here; }


That's what I'd recommend.
 
Share this answer
 
Comments
Codingnow20 7-Aug-18 11:44am    
i tagged it as c#
James McCullough 7-Aug-18 11:45am    
Sorry, yeah. Saw that AFTER I posted.
I actually figured this one out i put a counter for the names of the textboxes and a bool in the textchanged event handler.I then checked if the bool was true and if it was then i checked all the names to find which one was changed
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900