Results 1 to 2 of 2

Thread: Replace item in XML / listbox

  1. #1

    Thread Starter
    New Member
    Join Date
    Oct 2017
    Posts
    10

    Replace item in XML / listbox

    Hello,

    for an assignment for school I need to make an application that has a number of functions: read xml file into a listbox, add items to the listbox / xml and replace items in the xml and listbox.

    When replacing I don't know how to do this. There are 5 text boxes (name, country, region, grape, kind) that must be filled in.
    Then it must be checked whether they are unique and then these items in the list box must be searched for and replaced.



    An example of the xml being read :

    Public NotInheritable Class MainPage


    Inherits Page
    Dim xelement As XElement = XElement.Load("Assets/Wijnen.xml")
    Dim xWijnen As IEnumerable(Of XElement) = xelement.Elements()
    Dim Wijnen As XDocument = XDocument.Load("Assets/Wijnen.xml")



    Code:
        Private Sub WijnLijstBarButton_Click(sender As Object, e As RoutedEventArgs)
            Dim queryData = From Wijn In xWijnen.Descendants("Wijn")
                            Where (Wijn.Attribute("Land")).Value <> ""
                            Select Land = Wijn.Attribute("Land").Value,
                                   Naam = Wijn.Attribute("Naam").Value
                            Order By (Land)
    
            'De Namen en Landnamen van de wijnen worden toegevoegd in de ListBox.
            For Each xWijn In xWijnen
                WijnListBox.Items.Add(xWijn.@Land.PadRight(37, " ") & xWijn.@Naam.PadRight(30, " "))
            Next xWijn
    
    
        End Sub

    An attempt at the function. The name textbox must be filled in and then you have to check whether it exists in the listbox / xml file and replace it


    Code:
    Private Sub ButtonWijzig_Click(sender As Object, e As RoutedEventArgs) Handles ButtonWijzig.Click
     Dim queryDate = From Wijn In Wijnen.Descendants("Wijn")
                            Where (Wijn.Attribute("Naam").Value.Contains(TBNaam.Text.ToUpper.TrimEnd))
            For Each Wijn In queryDate
                WijnListBox.Items.Add(TBNaam.Text.PadRight(37, " ") & TBNaam.Text.PadRight(30, " "))
    
            Next

    Can someone help me out with this? Thanks in advance!
    Last edited by dday9; Aug 9th, 2021 at 05:22 PM.

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    110,297

    Re: Replace item in XML / listbox

    You describe a multistep process but you don't specify what step you are having a problem with. If it's multiple steps then that's part of the problem. In a multistep process, you should address one step at a time. You said:
    There are 5 text boxes (name, country, region, grape, kind) that must be filled in.
    Can you do that? If so then say so. If not then let's address that and so the rest is irrelevant and should not even be in the code you show us. Once that issue is addressed then you should create another thread for the next issue. Etc. Part of the reason that beginners have trouble solving problems is that they try to solve multiple problems as though they were one and each one obfuscates the others and nothing gets done. Stick to one problem at a time. You don't necessarily have to address them in one specific order, e.g. you can assume that all fields are populated and test that way and address the second step first. Just address one step at a time and, when you ask us about that step, be clear about what it is and provide all and only the information relevant to it.

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