Reputation: 41
I have a textbox and a button along side it. The button click opens a folder browser to a default root folder from which I can select the files. I want to display this entire file path in the textbox automatically when I launch the application. This is the code that I have now.
private void SelecttxtBox_TextChanged(object sender, System.Windows.Controls.TextChangedEventArgs e)
{
SelecttxtBox.Text = fldDlg.SelectedPath;
}
However, this inputs the path into the textbox AFTER the button click whereas I want to populate it BEFORE clicking on the button.
I appreciate the help, thank you
Upvotes: 1
Views: 1570
Reputation: 1096
Do you want to display the "default root" path in the Textbox on startup? If yes, then you can set the the Text Property simply in the constructor, then it should set it right when you start your application:
public MainWindow()
{
InitializeComponent();
SelecttxtBox.Text = "Whatever your root path is";
}
If you are new to WPF, I would as well suggest that you have a look into the MVVM pattern, as this is the "proper" way of how to separate Business Logic from the View, so not everything ends up in your code-behind.
Upvotes: 1