Results 1 to 4 of 4

Thread: My.Settings Updating when Combobox is filled

  1. #1

    Thread Starter
    Lively Member RichardKnox's Avatar
    Join Date
    Jul 2009
    Location
    Southern Michigan
    Posts
    89

    Question 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
    Thanks,
    Richard -
    --------
    -->Newbie Coder<<--
    Using VB.NET 2008/.NET 2.0/3.5

  2. #2
    PowerPoster stanav's Avatar
    Join Date
    Jul 2006
    Location
    Providence, RI - USA
    Posts
    9,290

    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.
    Let us have faith that right makes might, and in that faith, let us, to the end, dare to do our duty as we understand it.
    - Abraham Lincoln -

  3. #3

    Thread Starter
    Lively Member RichardKnox's Avatar
    Join Date
    Jul 2009
    Location
    Southern Michigan
    Posts
    89

    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
    Last edited by RichardKnox; Jun 14th, 2010 at 12:11 PM. Reason: Clairifying my request
    Thanks,
    Richard -
    --------
    -->Newbie Coder<<--
    Using VB.NET 2008/.NET 2.0/3.5

  4. #4
    PowerPoster stanav's Avatar
    Join Date
    Jul 2006
    Location
    Providence, RI - USA
    Posts
    9,290

    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.
    Let us have faith that right makes might, and in that faith, let us, to the end, dare to do our duty as we understand it.
    - Abraham Lincoln -

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width