0

I have a number of forms in my application.

A few of them display a pop up form which is similar to a browse file dialog. How can I return the folder path selected by the user back to the previous form?

BrowseTree bTree = new BrowseTree(connection); bTree.StartPosition = FormStartPosition.CenterParent; DialogResult dialogResult = bTree.ShowDialog(); 

The ShowDialog() shows the form. I can't figure out how to access the folder path selected within this BrowseTree form in the current form.

Please help.

5 Answers 5

2

You can pass data in many ways. Pass Data between forms

  1. via constructors
  2. via events
  3. via public properties

    public string _textBox1 {     get{return textBox1.Text;} } 

in form2 you can access like this

Form2 obj=new Form2(); string yourvalue=obj._textbox1; 
Sign up to request clarification or add additional context in comments.

Comments

1

Make a public Property in the BrowseTree class and set the folder path to it.

public class BrowseTree { public string YourProperty {get; set;} //some code } 

Then:

BrowseTree bTree = new BrowseTree(connection); bTree.StartPosition = FormStartPosition.CenterParent; DialogResult dialogResult = bTree.ShowDialog(); string value = bTree.YourProperty; 

2 Comments

I close the BrowseTree form using this.Close(); when the user clicks on a button. Will the property's value still exist?
Yes, if you set it in that form.
1

Not really sure what is BrowseTree class, you can use OpenFileDialog for this purpose. But if you have to use BrowseTree then define a property there for file path like:

public string FilePath {get;set;} 

Set that property against the object

bTree.FilePath = "Your file path"; 

Later you can use that in your calling form.

Comments

0

You should check here how it's done in classic OpenFileDialog. It has a property with selected file name and you can access it from another form.

2 Comments

I am aware of OpenFileDialog. But I can't use it since it is a custom browse section on a server.
@SoulSlayer I'm not suggesting that you should use it. I'm just giving you a reference to base on. What I mean is that it's already done it this dialog, so you can use the same solution, because it works.
0

You have to set a public property in parent form like:

public string path{get;set;} 

Then in child form close button:

parentobject.path="SelectedFolderPath";

hope this helps:

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.