Hi Ankit,
The textbox in the
btnAdd_Click()
event is not the same as the textbox in
ChooseFolder()
method. That is, the textbox in
ChooseFolder()
method is being instantiated and storing the value, but as soon as it gets out of the method, it perishes. So it doesn't store the value in the
btnAdd_Click()
event as that textbox is totally unaware of the other textbox.
I guess your business logic is:
1) Store the value of the path on 'Browse' button click.
2) Create array of controls and add the path in the textbox on 'Add' button click.
If this is the case, then the following changes will do.
string TextBoxValue = "";
public void ChooseFolder()
{
FolderBrowserDialog folderBrowserDialog1 = new FolderBrowserDialog();
if (folderBrowserDialog1.ShowDialog() == DialogResult.OK)
TextBoxValue = folderBrowserDialog1.SelectedPath;
}
Then add the line as indicated in the code below.
private void btnAdd_Click(object sender, EventArgs e)
{
int count = panel1.Controls.OfType<Label>().ToList().Count;
TextBox textbox = new TextBox();
count = panel1.Controls.OfType<TextBox>().ToList().Count;
textbox.Location = new Point(3, 25 * count);
textbox.Size = new Size(188, 20);
textbox.Name = "textbox_" + (count + 1);
textbox.Text = TextBoxValue;
textbox.TextChanged += new System.EventHandler(this.TextBox_Changed);
...............................
...............................
I hope that will solve the problem.