Click here to Skip to main content
15,885,925 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello,
I am fairly new to VB.NET and I am building a Windows Store app in VB.Net.
in my program I load an XML file, which I then display in a ListBox.

Which I have not yet succeeded, is modify an specific element in the listbox.
The user selects an element in the list box, which is then displayed in 5 different text boxes (name, country, region, grape, alcohol).

After that, the user adjusts a value in 1 of the text boxes. This value must then be found in the listbox and adjusted.


At the moment the search and adjustment does not yet work. I'm trying to search the list for the value of the textbox using LINQ, but I keep getting an empty value back.


I've been working on this for a while now but I don't see it anymore.
Can someone help me on my way?

What I have tried:

VB
Dim xelement As XElement = XElement.Load("Assets/Wines.xml")
Dim xWines As IEnumerable(Of XElement) = XElement.Elements()

Dim query = From Wine In xWines.Descendants("Wine")
             Where TBCountry.Text = Wine.Attribute("Country").Value _
             And TBName.Text = Wine.Attribute("Name").Value

        Select WName = Wine.Attribute("Name").Value,
               WCountry = Wine.Attribute("Country").Value


        For Each Wine In query
           Wines.Element("Name").SetValue(TBName.Text)
           Wines.Element("Country").SetValue(TBCountry.Text)
       
        Next Wine




Example of the XML file:

XML
<Wines>
<Wine Name="Canapi Grillo" Country="Italie" Region="Sicilie" Grape="Grillo" Alcohol="12"/>
<Wine Name="Miopasso Fiano" Country="Italie" Region="Sicilie" Grape="Fiano" Alcohol="13"/>
</Wines>
Posted
Updated 30-Aug-21 8:13am

1 solution

One possible way to achieve this is to use XmlSerialization[^].
Take a look here: A Complete Sample of Custom Class Collection Serialization and Deserialization[^]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900