My.Settings Updating when Combobox is filled
Code:
My.Settings.Current_DB
is bound to 'cbdatabase' which is a combobox which is filled by this method:
Code:
me.cbdatabase.datasource = (From foulder in New IO.DirectoryInfo("" & Application.StartUpPath & "\Database\").GetDirectories Select (folder.Name)).ToArray
I am using the My.Settings.Current_DB to keep track of the current database being used by the client. So that throughout the program and when the program starts up it knows what the current database is.
The databases and the folders have the same name, in order to keep track of.
My problem is when the combobox is filled when the program starts, it is overwriting the current info with the first item of the info loaded into the combo box.
ex:
Current_DB is "Default"
Program starts and it loads all the database names. The database names are
Alabama
Default
Michigan
Wisonsin
Instead of maintaining the Current_DB as "Default", it updates it with the first item into the Combobox and that is "Alabama".
How do I fix this so that it maintains the correct Current_DB and not update when the Combobox is filled.
Thanks
Re: My.Settings Updating when Combobox is filled
If you use property binding on the combobox then remove it and then set the value for that setting manually in the combobox.selectedindexchanged or selecteditemchanged event.
To load back the setting, after you set the datasource to your combobox, test if the setting is not empty and test if the list in the combobox contains the setting then you set the combobox.selectedindex to that item.
Re: My.Settings Updating when Combobox is filled
My next question is when I add a new directory/Database how would I update my datasource to see the new addition?
Code:
main.cbdatabase.datasource = (From folder In New IO.DirectoryInfo( " " & Application.StartupPath & "\Database\").GetDirectories Select Folder.Name)).Toarray
THis fills my combobox initially, I want to know how to force an update after creating a new directory/database?
Thanks
Re: My.Settings Updating when Combobox is filled
You will have to use a FileSystemWatcher object to watch that directory for changes and and run that very same line of code again when you receive an event from the filesystemwatcher object. Search the forum for examples if you don't already know how to use the FSW component.