propagate a combobox dropdown list with a LINQ to XML query

EDN Admin

Well-known member
Joined
Aug 7, 2010
Messages
12,794
Location
In the Machine
Noob question
Im trying to fill a combobox dropdown list with a LINQ to XML query. Im able to load the xdocument and query the document for different elements. I would like to use one of these queries as the basis of the combobox list.
the following XML is a dynbamic recipe database. It is updated by the user and new recipes are added. I would like the dropdown list to be propagated from the XML file so as the XML changes so does the dropdown list. The element "NAME" is
the basis for the combobox list I want.
<pre class="prettyprint <?xml version="1.0" encoding="utf-8"?>
<RECIPES>
<RECIPE>
<NAME>MAMAS PIE</NAME>
<STYLE>OLD FASHIONED</STYLE>
<CHEF>MAMA</CHEF>
<DATE>DEC 8 2012</DATE>
<APPLES>
<APPLE>
<NAME>MACINTOSH</NAME>
<COLOR>RED</COLOR>
<SWEETNESS>1</SWEETNESS>
</APPLE>
<APPLE>
<NAME>GOLDEN DELICIOUS</NAME>
<COLOR>GOLD</COLOR>
<SWEETNESS>2</SWEETNESS>
</APPLE>
</APPLES>
<SUGARS>
<SUGAR>
<NAME>TRUCKLE</NAME>
<COLOR>BROWN</COLOR>
<PRICE>2.25</PRICE>
</SUGAR>
</SUGARS>
</RECIPE>
<RECIPE>
<NAME>DADS PIE</NAME>
<STYLE>NEW AGE</STYLE>
<CHEF>DAD</CHEF>
<DATE>DEC 10 2012</DATE>
<APPLES>
<APPLE>
<NAME>GALA</NAME>
<COLOR>PINK</COLOR>
<SWEETNESS>3</SWEETNESS>
</APPLE>
<APPLE>
<NAME>GRANNY SMITH</NAME>
<COLOR>GOLD</COLOR>
<SWEETNESS>4</SWEETNESS>
</APPLE>
</APPLES>
<SUGARS>
<SUGAR>
<NAME>CANE</NAME>
<COLOR>WHITE</COLOR>
<PRICE>1.5</PRICE>
</SUGAR>
</SUGARS>
</RECIPE>
</RECIPES>[/code]

here is the Visual basic code I have right now. the query returns the following:

<pre class="prettyprint Imports System.Xml
Imports System.IO

Public Class Form1

Public piepath As String = "C:UserspeteDesktopobject programmingxml data readingsorting xml data and sending to datagridXMLtestpies.xml"

Public doc As XDocument = XDocument.Load(piepath)

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

Dim query =
From el In doc.Descendants("RECIPE")
Select New With {
el.Element("NAME").Value
}

ComboBox1.DataSource = query.ToList


End Sub
End Class<br/>[/code]

The combobox is being propagated with the following:
{ Value = MAMAS PIE }
{ Value = DADS PIE }
My question is: how do I get the list to be propagated with "MAMAS PIE" and "DADS PIE" as opposed to the other formatting and value syntax.

Thank you in advance for any help

Pete



View the full article
 
Back
Top