1 Replies - 581 Views - Last Post: 11 April 2013 - 09:13 AM Rate Topic: -----

#1 Sashac2013  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 1
  • Joined: 11-April 13

Bind XML File to Drop-Down box

Posted 11 April 2013 - 08:27 AM

I have an XML file that will be updated frequently and the contents of the file need to be displayed in a drop-down list. I've found many code snippets but none seem to work. I'm new at VB and not sure what I'm doing wrong. The file can be read and displayed in a console but for some reason it won't display in the drop-down. Here is the xml file:
<?xml version="1.0" encoding="UTF-8"?>
<acronymList>
  <folder>
  <acm> C01</acm> 
    <descrip>Correspondence </descrip>
    
    <acm> AWB </acm>
      <descrip> Air Way Bill </descrip>

    <acm> EMO </acm>
      <descrip>Equipment Movement Order</descrip>
    
    <acm> FRF </acm> 
      <descrip>Frieght Request Form </descrip>
   
    <acm> IVF </acm>
      <descrip>Invoice, Frieght, and Duty </descrip>
    
    <acm> TMN </acm> 
      <descrip> Transmittal Note </descrip>
  </folder>
    
</acronymList> 


And here is the code:

Imports System.IO
Imports System.Xml
Imports System.Data


Public Class Form1

    Private Sub ComboBox1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ComboBox1.SelectedIndexChanged
        Dim dsdata As New DataSet
        dsdata.ReadXml("C:\Users\CDawson2\Dropbox\Test\testxml.xml")
        ComboBox1.DataSource = dsdata.Tables(0)
        ComboBox1.DisplayMember = dsdata.Tables(0).Columns(0).ColumnName


    End Sub

   
    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        
    End Sub
End Class  


Is This A Good Question/Topic? 0
  • +

Replies To: Bind XML File to Drop-Down box

#2 tlhIn`toq  Icon User is offline

  • Please show what you have already tried when asking a question.
  • member icon

Reputation: 5476
  • View blog
  • Posts: 11,762
  • Joined: 02-June 10

Re: Bind XML File to Drop-Down box

Posted 11 April 2013 - 09:13 AM

When does the combobox get loaded with data?

You have a handler for when the form loads. That does nothing.

You have a handler for when the selection changes in the combobox.
And when the selection changes then you start reading the file.
That doesn't make sense, does it? Only after you make a selection do you populate the combobox. But how *can* you make a selection if there is nothing in it.

Perhaps you should populate the combobox when the form loads. Then it would contain something for you to select.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1