Results 1 to 3 of 3

Thread: How do I modify an specific element in my listbox?

  1. #1

    Thread Starter
    New Member
    Join Date
    Oct 2017
    Posts
    10

    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>

  2. #2
    Fanatic Member Delaney's Avatar
    Join Date
    Nov 2019
    Location
    Paris, France
    Posts
    846

    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.
    The best friend of any programmer is a search engine
    "Don't wish it was easier, wish you were better. Don't wish for less problems, wish for more skills. Don't wish for less challenges, wish for more wisdom" (J. Rohn)
    “They did not know it was impossible so they did it” (Mark Twain)

  3. #3
    Wall Poster TysonLPrice's Avatar
    Join Date
    Sep 2002
    Location
    Columbus, Ohio
    Posts
    3,969

    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.
    Please remember next time...elections matter!

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width