Dear Friends,
I have a question about the mentioned problem in the title.
I have a main window where I have plenty of labels that I use as buttons. Each label has its own name, like apple, orange, stone, pencil...anything. Each label have a lot of values assigned to it.
So, when I click one of these, a new textbox is being generated. The name of the textbox will be the name of the layer +"txtbox1". So, for example: appletxtbox1. Let's say, I create a second textbox at the same time with the name appletxtbox2. Also, let's say, that the textbox1 contains the weight of the apple in kg, and the textbox2 in lbs. Then, I want to manually refresh the value of the textbox2 which contains the weight in lbs and based on that I want to refresh the value in the textbox1, by using the TextBoxChanged event handler. I try to describe it better by showing the actual part of the code.
What I have tried:
TextBox txtbxAt;
Label labi = sender as Label;
private void setLabelClick(object sender, EventArgs e)
{
txtbxAt = new TextBox();
txtbxAt.Name = labi.Text+"AtBox";
txtbxAt.Text = element.SomeValue.ToString();
txtbxAt.TextChanged += new EventHandler(txtbxAt_TextChanged);
groupBox3.Controls.Add(txtbxAt);
}
So, based on the above code, I can create the textbox dynamically and I can write in it. But, then if there is a similar textbox, I cannot make them "crosstalk". So, when I am in the eventhandler, I cannot refresh the other textbox by writing in it. I tested the eventhandler by just making a pop up messagebox and printing some of the values I use. That was successful, so the eventhandler can see the values I want to work with.
In the textbox's textchanged eventhandler, I want to do something like
(f.Symbol+"AtBox").Text = f.SomeValue.ToString();
, where f is just an element which I know by the labels I click. So when I type in the box1, I want to update box2 and vice-versa.
But of course the compiler will look at me funnily when I try to make the above -obviously- wrong code work.
Can you tell me any suggestions about how to reach a dynamically created textbox and refresh its value based on the value of another dynamically created textbox?
Thank you in advance!