Results 1 to 9 of 9

Thread: [RESOLVED] [2005] Application Properties Question

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    Aug 2006
    Location
    In my head
    Posts
    913

    Resolved [RESOLVED] [2005] Application Properties Question

    Currently I have an admin page that has 2 listboxes. One has a list of states that once one is selected supplies a list of counties for the other listbox. Both are set using the listboxes datasource property set to a stringcollection in the application settings.

    I am also setting it up so that you can add item(s) to the state list. When an item is added to the state list it also adds a new countylist to the application settings (as a string collection).

    The good news is that all this works fine. The problem I have is that when a user adds a new state, how do I reference the associated county list? I started with a case statement but once a user adds a value the case statement goes out the window. I tried to access it using
    Code:
    My.Settings.Properties.Item(st & "CountyList")
    No good. Any ideas??

    Thanks,

    D
    Platforms of choice: Visual Studio 2005/2008 Professional : Visual Studio 2010 Enterprise : PHP - Notepad++/WAMP

    Please Rate If I helped you.
    Please remember to mark threads as closed if your issue has been resolved.

    Reserved Words in Access | Connection Strings

  2. #2
    I'm about to be a PowerPoster! kleinma's Avatar
    Join Date
    Nov 2001
    Location
    NJ - USA (Near NYC)
    Posts
    23,373

    Re: [2005] Application Properties Question

    maybe im confused, when the user picks a state the other list fills with countries??? or is it the other way around?

    Either way, how are you making you associations between the 2 collections now? IE, how do you determine what items to load in list2 when a user makes a selection in list1?

  3. #3

    Thread Starter
    Fanatic Member
    Join Date
    Aug 2006
    Location
    In my head
    Posts
    913

    Re: [2005] Application Properties Question

    maybe im confused, when the user picks a state the other list fills with countries??? or is it the other way around?
    LOL not countries, counties within each state (i.e. Lancaster County, Pennsylvania). To populate the box I have a string collection setup for each state so for example if the user picks "MD" as their state the county list box databinds to the string collection "MDCountyList". Which is stored in the application.settings. This may not be the "best" way, which is why I am here!!

    Anyways, thanks for taking a look kleinma.

    D

    EDIT: My ultimate goal is to have a list of states that a user can edit and a list of counties for each state (kind of like a master detail kind of thing). I need to make it available to the entire application which is why I chose application settings. I may just have to use XML though huh?
    Platforms of choice: Visual Studio 2005/2008 Professional : Visual Studio 2010 Enterprise : PHP - Notepad++/WAMP

    Please Rate If I helped you.
    Please remember to mark threads as closed if your issue has been resolved.

    Reserved Words in Access | Connection Strings

  4. #4
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: [2005] Application Properties Question

    Why not use DB tables?

  5. #5

    Thread Starter
    Fanatic Member
    Join Date
    Aug 2006
    Location
    In my head
    Posts
    913

    Re: [2005] Application Properties Question

    That is certainly an option and one I have considered. I was hoping to keep them separate but in trying to finish up this app quickly, I may not have a choice....

    Thanks Hack!

    D
    Platforms of choice: Visual Studio 2005/2008 Professional : Visual Studio 2010 Enterprise : PHP - Notepad++/WAMP

    Please Rate If I helped you.
    Please remember to mark threads as closed if your issue has been resolved.

    Reserved Words in Access | Connection Strings

  6. #6
    I'm about to be a PowerPoster! kleinma's Avatar
    Join Date
    Nov 2001
    Location
    NJ - USA (Near NYC)
    Posts
    23,373

    Re: [2005] Application Properties Question

    why not use an XML file??? You can store it in the application settings, you can edit/append the XML file (its just text) by loading it up into an XMLDocument class, and you can store it back in your settings.

    It would look something like this:

    Code:
    <?xml version="1.0" encoding="utf-8" ?>
    <states>
      <state>
        <name>Some State</name>
        <county>Some County 1</county>
        <county>Some County 2</county>
        <county>Some County 3</county>
      </state>
      <state>
        <name>Some Other State</name>
        <county>Some Other County 1</county>
        <county>Some Other County 2</county>
        <county>Some Other County 3</county>
      </state>
    </states>
    This code should get you started (added the above XML as a user setting string called MyXML)

    Code:
    imports system.xml 'at top
    
            'CREATE XML DOCUMENT
            Dim XMLDoc As New XmlDocument
            'LOAD ITS CONTENTS FROM THE APPLICATION SETTINGS
            XMLDoc.LoadXml(My.Settings.MyXML)
    
            'STRING BUILDER IS JUST TO DISPLAY THE OUTPUT FOR THE EXAMPLE
            Dim Output As New System.Text.StringBuilder
    
            'FOR EACH STATE ELEMENT IN THE XML FILE, LOOP AND GET ITS NAME
            For Each State As XmlElement In XMLDoc.DocumentElement.GetElementsByTagName("state")
                Output.AppendLine("State: " & State.Item("name").InnerText)
                Output.AppendLine()
                Output.AppendLine("Counties:")
                'THEN FOR EACH COUNTY ELEMENT INSIDE THE GIVEN STATE ELEMENT, GET THE COUNTY NAME
                For Each County As XmlElement In State.GetElementsByTagName("county")
                    Output.AppendLine(County.InnerText)
                Next
                Output.AppendLine()
                Output.AppendLine()
            Next
            'SHOW OUTPUT
            MessageBox.Show(Output.ToString)

  7. #7

    Thread Starter
    Fanatic Member
    Join Date
    Aug 2006
    Location
    In my head
    Posts
    913

    Re: [2005] Application Properties Question

    I am getting an error when I try to loadxml. It is saying "Data at the root level is invalid Line 1 Position 1. Here is the xml file:
    Code:
    <? xml version="1.0" encoding="utf-8" ?>
    <states>
     <state>
        <name>DE</name>
        <county>New Castle</county>
        <county>Kent</county>
        <county>Sussex</county>
     </state>
     <state>
        <name>MD</name>
        <county>Anne Arundel</county>
        <county>Caroline</county>
        <county>Cecil</county>
        <county>Kent</county>
        <county>Prince George's</county>
        <county>Queen Anne's</county>
        <county>Talbot</county>
      </state>
      <state>
        <name>NJ</name>
        <county>Atlantic</county>
        <county>Bergen</county>
        <county>Burlington</county>
        <county>Camden</county>
        <county>Cape May</county>
        <county>Cumberland</county>
        <county>Essex</county>
        <county>Gloucester</county>
        <county>Hudson</county>
        <county>Hunterdon</county>
        <county>Mercer</county>
        <county>Middlesex</county>
        <county>Monmouth</county>
        <county>Morris</county>
        <county>Ocean</county>
        <county>Passaic</county>
        <county>Salem</county>
        <county>Somerset</county>
        <county>Sussex</county>
        <county>Union</county>
        <county>Warren</county>
      </state>
      <state>
        <name>PA</name>
        <county>Montgomery</county>
        <county>Bucks</county>
        <county>Philadelphia</county>
        <county>Snyder</county>
      </state>
    </states>
    Here is the line of code that errors on me:
    Code:
    xmlStateCountyList.LoadXml(My.Settings.StateXMLLoc)
    I am researching google as we speak. Hoping for a quick easy answer.
    Platforms of choice: Visual Studio 2005/2008 Professional : Visual Studio 2010 Enterprise : PHP - Notepad++/WAMP

    Please Rate If I helped you.
    Please remember to mark threads as closed if your issue has been resolved.

    Reserved Words in Access | Connection Strings

  8. #8

    Thread Starter
    Fanatic Member
    Join Date
    Aug 2006
    Location
    In my head
    Posts
    913

    Re: [2005] Application Properties Question

    Nevermind, I got it figured out. I am using an external doc so I need to use the Load method. Thanks kleinma for your help.

    D
    Platforms of choice: Visual Studio 2005/2008 Professional : Visual Studio 2010 Enterprise : PHP - Notepad++/WAMP

    Please Rate If I helped you.
    Please remember to mark threads as closed if your issue has been resolved.

    Reserved Words in Access | Connection Strings

  9. #9
    I'm about to be a PowerPoster! kleinma's Avatar
    Join Date
    Nov 2001
    Location
    NJ - USA (Near NYC)
    Posts
    23,373

    Re: [2005] Application Properties Question

    this
    <? xml version="1.0" encoding="utf-8" ?>
    shoudl be this
    <?xml version="1.0" encoding="utf-8" ?>

    note no space after the ?

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