VB.net populate combobox from xml file

i have a vb.net windows forms application.  I want to read in an xml file and populate a combo box
Here is the an example of what will be in the xml file
<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<Main>
  <SiteInfo>
    <Element Name="NewYork" Value="9.9.9.9" />
    <Element Name="LA" Value="2.2.2.2" />
    <Element Name="Boston" Value="3.3.3.3" />
  </SiteInfo>
</Main>

Open in new window


I want to read in the information from the xml file and have the Name be the text entry (what is displayed to the user) for a combo box and the value be the value of the combo box... for the life of me I cant figure it out

the comobox name = cmbSiteInfo

Thanks so much for the help
David ModugnoAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

it_saigeDeveloperCommented:
Like this:

Form1.vb -
Public Class Form1
	Private Sub OnLoad(sender As Object, e As EventArgs) Handles MyBase.Load
		Dim xelement As XElement = XElement.Load("Locations.xml")
		Dim locations As IEnumerable(Of XElement) = xelement.Descendants("SiteInfo").Descendants("Element")
		ComboBox1.DataSource = (From element In locations Select New With {.Display = element.Attribute("Name").Value, .Value = element.Attribute("Value").Value}).ToList()
		ComboBox1.DisplayMember = "Display"
		ComboBox1.ValueMember = "Value"
	End Sub
End Class

Open in new window

Form1.Designer.vb -
<Global.Microsoft.VisualBasic.CompilerServices.DesignerGenerated()> _
Partial Class Form1
	Inherits System.Windows.Forms.Form

	'Form overrides dispose to clean up the component list.
	<System.Diagnostics.DebuggerNonUserCode()> _
	Protected Overrides Sub Dispose(ByVal disposing As Boolean)
		Try
			If disposing AndAlso components IsNot Nothing Then
				components.Dispose()
			End If
		Finally
			MyBase.Dispose(disposing)
		End Try
	End Sub

	'Required by the Windows Form Designer
	Private components As System.ComponentModel.IContainer

	'NOTE: The following procedure is required by the Windows Form Designer
	'It can be modified using the Windows Form Designer.  
	'Do not modify it using the code editor.
	<System.Diagnostics.DebuggerStepThrough()> _
	Private Sub InitializeComponent()
		Me.ComboBox1 = New System.Windows.Forms.ComboBox()
		Me.SuspendLayout()
		'
		'ComboBox1
		'
		Me.ComboBox1.FormattingEnabled = True
		Me.ComboBox1.Location = New System.Drawing.Point(13, 13)
		Me.ComboBox1.Name = "ComboBox1"
		Me.ComboBox1.Size = New System.Drawing.Size(259, 21)
		Me.ComboBox1.TabIndex = 0
		'
		'Form1
		'
		Me.AutoScaleDimensions = New System.Drawing.SizeF(6.0!, 13.0!)
		Me.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font
		Me.ClientSize = New System.Drawing.Size(284, 59)
		Me.Controls.Add(Me.ComboBox1)
		Me.Name = "Form1"
		Me.Text = "Form1"
		Me.ResumeLayout(False)

	End Sub

	Friend WithEvents ComboBox1 As ComboBox
End Class

Open in new window

Which produces the following output -Capture.PNG
-saige-
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
David ModugnoAuthor Commented:
Thank you... i will give that a try
0
David ModugnoAuthor Commented:
Worked perfectly.. thank you
0
it_saigeDeveloperCommented:
Glad to be of assistance...
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic.NET

From novice to tech pro — start learning today.