How do I modify an specific element in my listbox?
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:
Code:
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:
Code:
<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>
Re: How do I modify an specific element in my listbox?
Personally, I would have added an unique ID to each element so when I select an element I get the ID and then it is easier to find it afterward. I also would not change the listbox but directly the file and then update the listbox with the new updated file.
Re: How do I modify an specific element in my listbox?
I agree with Delaney...otherwise at some point you have to update the source. Looking at the selected item should save having to look things up.