CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2
  1. #1
    Join Date
    Jun 2005
    Posts
    5

    Question Populating textboxes from a XML file.

    I have a XML file in a configuration similar to the example below, now I have been able to load the XML file into my VB application and populate a Combo Box with all the Location tag infomation.

    <Server>
    <Location>Home</Location>
    <Info1>String</Info1>
    <Info2> String</Info2>
    </Server>

    Now what I can not seem to figure out how to do is that when I select an item from the combo box list. I would like to populate text boxes on the application form with the information from tags Info1 and Info2 based on the Location Tag selected.

    Does anyone have any ideas on how to do this? I have been poaring over the MSXML 4.0 documentation all morning with little results.

    Cheers,
    Thom

  2. #2
    Join Date
    Jul 2003
    Location
    Florida
    Posts
    651

    Re: Populating textboxes from a XML file.

    1. Create a class (called ServerClass or something like that) to store the data from the XML.
    Code:
    Option Explicit
    
    Public ServerLocation As String
    Public ServerInfo1 As String
    Public ServerInfo2 As String
    2. Populate the collection as you read from your XML string and Add it to a Collection.
    Code:
    Dim clsServerClass As ServerClass
    Dim colServerCollection As Collection
    
    Set colServerCollection = New Collection
    
    Do Until (End of XML File)
        Set clsServerClass = New ServerClass
    
        clsServerClass.ServerLocation = (XML Location)
        clsServerClass.ServerInfo1 = (XML Info1)
        clsServerClass.ServerInfo2 = (XML Info1)
    
        colServerCollection.Add clsServerClass, clsServerClass.ServerLocation  'Set ServerLocation to the Collection Key only if it's unique
    Loop
    3. When you choose from the combobox, fetch the correct Class info from the collection and use it to populate your textboxes:
    Code:
    Dim clsServerClass As ServerClass
    
    Set clsServerClass = colServerCollection(Combobox.Text)  'Assuming that you populate the combobox with the ServerLocation
    
    txtLocation.Text = clsServerClass.ServerLocation
    txtInfo1.Text = clsServerClass.ServerInfo1
    txtInfo2.Text = clsServerClass.ServerInfo2
    I'd rather be wakeboarding...

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

Featured