Quantcast
Channel: VBForums
Viewing all articles
Browse latest Browse all 15516

Replace item in XML / listbox

$
0
0
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!

Viewing all articles
Browse latest Browse all 15516

Trending Articles