Results 1 to 6 of 6

Thread: XmL file is not loading in Listbox

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Oct 2007
    Posts
    270

    XmL file is not loading in Listbox

    I have vb code along with xml.and i need to populate simple xml file in list box in silverlight appliction ,but its not rendering any thing
    Code:
    <UserControl xmlns:controls="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls"  xmlns:data="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls.Data"  x:Class="SilverlightApplication1.MainPage"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
        mc:Ignorable="d" d:DesignWidth="640" d:DesignHeight="480">
    
        <Grid x:Name="LayoutRoot" Background="White">
            <ListBox x:Name="customersList" Width="400" Height="200" />
        </Grid>
    </UserControl>
    Code:
    Private Sub PopulateCustomersList()
            Dim settings As New XmlReaderSettings()
            settings.XmlResolver = New XmlXapResolver()
            Dim reader As XmlReader = XmlReader.Create("Customers.xml")
            reader.MoveToContent()
            While reader.Read()
                If reader.NodeType = XmlNodeType.Element AndAlso reader.Name = "customer" Then
                    customersList.Items.Add(New ListBoxItem())
                End If
                If reader.NodeType = XmlNodeType.EndElement AndAlso reader.Name = "customers" Then
                    Exit While
                End If
            End While
            reader.Close()
        End Sub
    Code:
     Private Sub Btn_hello_Click(ByVal sender As System.Object, ByVal e As System.Windows.RoutedEventArgs)
    
            MessageBox.Show("Hello World")
    
            PopulateCustomersList()
               End Sub

  2. #2

    Thread Starter
    Hyperactive Member
    Join Date
    Oct 2007
    Posts
    270

    Re: XmL file is not loading in Listbox

    here is the .xml file
    Code:
    <?xml version="1.0"?>
    <customers>
      <customer id="10001" first="John" last="Smith" company="Donuts plc">jsmith@mymail.com</customer>
      <customer id="10002" first="Rete" last="Bandy" company="This Is Bloggers Co.">rete@superbloggers.com</customer>
      <customer id="10003" first="James" last="Bird" company="Timestone">james.bird@timestone.co.uk</customer>
      <customer id="10004" first="Sarah" last="McCauly" company="Automated Snowmen Ltd">smccauly@automatedsnowmen.com</customer>
      <customer id="10005" first="Pete" last="Rowan" company="Cooltec Consultants">pete.rowan@cooltec.com</customer>
    </customers>

  3. #3
    Smooth Moperator techgnome's Avatar
    Join Date
    May 2002
    Posts
    34,532

    Re: XmL file is not loading in Listbox

    What's a ListBoxItem? Doesn't surprise me nothing is rendering... I don't see where you extract any data from the XML and add it to the ListBox.

    -tg
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  4. #4

    Thread Starter
    Hyperactive Member
    Join Date
    Oct 2007
    Posts
    270

    Re: XmL file is not loading in Listbox

    took reference from here
    http://www.vectorlight.net/tutorials...lverlight.aspx

    and out put is showing over there

  5. #5
    Smooth Moperator techgnome's Avatar
    Join Date
    May 2002
    Posts
    34,532

    Re: XmL file is not loading in Listbox

    of course THAT example works... the data was extracted from the XML:
    Code:
     customersList.Items.Add(new ListBoxItem() { Content = reader.GetAttribute("last") +                        ", " + reader.GetAttribute("first") + " (" + reader.ReadInnerXml() + ")" });
    When you copied it over and converted it to VB, you didn't inlcude the reader.GetAttribute parts...

    -tg
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  6. #6

    Thread Starter
    Hyperactive Member
    Join Date
    Oct 2007
    Posts
    270

    Re: XmL file is not loading in Listbox

    hmm, fair enough can u please correct the missing statment in this i.e
    Code:
     While reader.Read()
                If reader.NodeType = XmlNodeType.Element AndAlso reader.Name = "customer" Then
                    customersList.Items.Add(New ListBoxItem() Content = reader.GetAttribute("last") & ", " & reader.GetAttribute("first") & " (" & reader.ReadInnerXml() & ")" & )
                End If
                If reader.NodeType = XmlNodeType.EndElement AndAlso reader.Name = "customers" Then
                    Exit While
                End If
            End While

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