In a new C# 2010 windows form application that I will be writing, I have the following items to mention:
1. The form will have the following 2 places for the user to select/enter data:
a. customer id, and b. a window where the user can select the directory path of
where they want to select a file from.
2. There will also be a submit button to click to show all the data has been entered, and
3. an area that will show when an invalid customer id has been entered.
4. The following is a url that I know that I can use as a reference for allowin the user to select
the directory of the file they want to use: http://msdn.microsoft.com/en-us/library/system.windows.forms.openfiledialog.aspx.
Now I have the following questions to ask:
1. How would I setup a default directory for where the file should be located?
2. How should I setup code that will allow the user to select the directory path of where a file is located at? Do you need to have an extra button for the user to be able to 'select' the directory path?
3. How Do I take the values that have been entered on the windows form and pass the values back to the main method that called the windows form?
4. Can you show me code how on to tell the user they entered an invalid customer id?
Loading
VulpesPosted Jun 12, 2013, 7:05 PM
This is because, if you look at a typical WPF application in VS, the Program class and Main() method are nowhere to be seen!
The Main() method is actually generated automatically by the WPF infrastructure and whilst you can create your own this is all rather awkward to deal with.
Check out this blog post for a description of what actually happens here:
http://joyfulwpf.blogspot.co.uk/2009/05/where-is-main-method-in-my-wpf.html
Sie StePosted Jun 12, 2013, 6:10 PM
My question now is how about if I want to use WPF (windows presentation foundation) instead of a desktop form application? What logic would I use differently? Would all the logic you mentioned above be the same or different? If the code is different, can you show me some code of what would be different?
VulpesPosted Jun 12, 2013, 5:01 AM
1. Open a FolderBrowserDialog with its SelectedPath property set to your 'default' directory to enable the user to choose a sub-folder within that directory.
2. Then open an OpenFileDialog (with its InitialDirectory property set to the sub-folder chosen) to enable the user to select an Excel file within that sub-folder.
However, the trouble with all this is that these dialogs can't prevent the user browsing the file system and choosing some folder or file which is inappropriate.
If you want to prevent that then it would be better (say) to load all the sub-folder names into a ListBox and get the user to select one and then display all the Excel files in that subfolder in another ListBox so that one (or more) of those files can then be chosen.
Sie StePosted Jun 11, 2013, 11:41 PM
Thus how would I set a default directory, but make the user seelct the subfolder they want to access and then select the file(s) they need? Would you show me some code?
VulpesPosted Jun 11, 2013, 7:28 PM
http://msdn.microsoft.com/en-us/library/system.windows.forms.folderbrowserdialog.aspx