0

I've got a button that saves the path to a folder as the text in a text box and I want to save it to the settings file in c# but I keep getting the error:

Cannot implicitly convert type "System.windows.type.textbox" to String

Now the code I'm using to set the text box as the path is:

folderBrowserDialog1.ShowDialog();
textBox1.Text = folderBrowserDialog1.SelectedPath;

And the code I'm using to save it to the settings file is:

string pathh = textBox1;
Properties.Settings.Default.Path = textBox1;

Even if I replace

Properties.Settings.Default.Path = textBox1
Properties.Settings.Default.Path = pathh

I get the same error. Can some one tell me how to fix this please?

2 Answers 2

3

Your path is not the textbox but the TEXT of the textbox, so change

Properties.Settings.Default.Path = textBox1;

to

Properties.Settings.Default.Path = textBox1.Text;
Sign up to request clarification or add additional context in comments.

Comments

2

Use the Text property of TextBox control class which is of String type like below. What you are trying is assigning a control instance to string and so receiving the error cause there are not same type.

string pathh = textBox1.Text; 

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.