Click here to Skip to main content
14,240,610 members
Rate this:
Please Sign up or sign in to vote.
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
Rate this:
Please Sign up or sign in to vote.

Solution 2

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;
}
   
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
Rate this:
Please Sign up or sign in to vote.

Solution 1

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.
   
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.
Rate this:
Please Sign up or sign in to vote.

Solution 3

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
   

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




CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100