CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2
  1. #1
    Join Date
    Mar 2011

    Silly problem I just cant seem to solve-Combo box set

    I am new to XAML so apologies about this simple problem. I have a combobox on a page. When I try to set the comboxbox to a value read from a database I keep getting a null error. I am guessing its because I am using the selecteditem bit and as the combobox hasnt got anything selected it errors.. but that is only a gues

    Design bit
    <ComboBox x:Name="cbox1" IsEnabled= "False" SelectionChanged="cbox1_SelectionChanged" Width="200" Margin="10,0,0,0" Height="60" Grid.Column="1" FontSize="20" >
    <ComboBoxItem Tag="3" >0</ComboBoxItem>
    <ComboBoxItem Tag="4">50</ComboBoxItem>
    <ComboBoxItem Tag="5">100</ComboBoxItem>
    <ComboBoxItem Tag="6">150</ComboBoxItem>
    <ComboBoxItem Tag="7">200</ComboBoxItem>
    <ComboBoxItem Tag="8">250</ComboBoxItem>
    <ComboBoxItem Tag="9">300</ComboBoxItem>
    <ComboBoxItem Tag="10">350</ComboBoxItem>


    Code behind

    SetResult = "600"; // This is where try to set the value in the box


    public string SetResult
    if (cbox1.SelectedIndex != -1)
    { return ((ComboBoxItem)cbox1.SelectedItem).ToString(); }
    { return ""; }
    ((ComboBoxItem)cbox1.SelectedItem).Content = value;

    Can you anyone point out my obvious stupid mistake


  2. #2
    Arjay's Avatar
    Arjay is online now Moderator / MS MVP Power Poster
    Join Date
    Aug 2004

    Re: Silly problem I just cant seem to solve-Combo box set

    Put a breakpoint on
    ((ComboBoxItem)cbox1.SelectedItem).Content = value;
    and verify that cbox1.SelectedItem and value are valid.

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

Windows Mobile Development Center

Click Here to Expand Forum to Full Width

On-Demand Webinars (sponsored)

We have made updates to our Privacy Policy to reflect the implementation of the General Data Protection Regulation.