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

    Resolved Pre-setting the ComboBox selection in XAML

    Colleagues,

    I would like to pre-set the ComboBox in XAML. For example, there are 3 options: “4800”, “9600”, “19200”. I know that the text of the pre-selected item is “9600”. Which properties of ComboBox should I assign? Is it possible to do it entirely in XAML without writing code for looking up the index from the item text.

    So far, I’ve tried this:
    Code:
            <ComboBox Name="cboBaudRate" 
                      Grid.Column="1" Grid.Row="1" Margin="0,2,0,0" HorizontalAlignment="Left" Width="72" Height="20" VerticalAlignment="Top"
                      SelectedItem="9600" IsSynchronizedWithCurrentItem="True"
                      ItemsSource="{Binding Source={StaticResource SerialPortOptions}, XPath=./BaudRates/BaudRate }" />
    But it keeps selecting the 1st option “4800”, probably because the index is initially set to 0.

    Suggestions, insight, references are much appreciated.

    - Nick
    Last edited by kender_a; January 22nd, 2010 at 03:57 PM.

  2. #2
    Join Date
    May 2001
    Location
    Silicon Valley
    Posts
    113

    Resolved Re: Pre-setting the ComboBox selection in XAML

    Resolved. Assigning SelectedValue instead of SelectedItem worked.

    The working XAML looks like this:
    Code:
            <ComboBox Name="cboBaudRate" 
                      Grid.Column="1" Grid.Row="1" Margin="0,2,0,0" HorizontalAlignment="Left" Width="72" Height="20" VerticalAlignment="Top"
                      SelectedValue="9600"
                      ItemsSource="{Binding Source={StaticResource SerialPortOptions}, XPath=./BaudRates/BaudRate }" />

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