CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2
  1. #1
    Join Date
    May 2001
    Location
    Silicon Valley
    Posts
    113

    Question Binding ComboBox to XML data. Having a problem.

    Folks,

    I was able to bind my ComboBox to an XML file, but there’s a “small cosmetic” problem. The data in the XML file looks like this:
    Code:
    <?xml version="1.0" encoding="UTF-8"?>
    <Options>
      <BaudRates>
        <BaudRate>4800</BaudRate>
        <BaudRate>9600</BaudRate>
        <BaudRate>19200</BaudRate>
      </BaudRates>
    </Options>
    But the ComboBox displays it all in one item: 4800960019200
    The binding is done entirely in XAML:
    Code:
            <ComboBox Name="cboBaudRate" Grid.Column="1" Grid.Row="1" Margin="0,2,0,0" HorizontalAlignment="Left" Width="72" Height="20" VerticalAlignment="Top" >
                <ComboBox.ItemsSource>
                    <Binding Source="{StaticResource SerialPortOptions}" XPath="./BaudRates" /> 
                </ComboBox.ItemsSource> 
            </ComboBox>
    How can I display each XML item as a separate ComboBox item?

    Of course, I can post more snippets if needed.

    Thanks,
    - Nick

  2. #2
    Join Date
    Sep 2002
    Location
    14° 39'19.65"N / 121° 1'44.34"E
    Posts
    9,815

    Re: Binding ComboBox to XML data. Having a problem.

    You need to select the individual item node in your XPath expression, like this:

    Code:
    <ComboBox.ItemsSource>
                    <Binding Source="{StaticResource SerialPortOptions}" XPath="./BaudRates/BaudRate" /> 
    </ComboBox.ItemsSource>

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

Featured