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
    Posts
    3

    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>

    </ComboBox>

    Code behind
    -----------

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


    code.....

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


    Can you anyone point out my obvious stupid mistake

    thanks

  2. #2
    Arjay's Avatar
    Arjay is offline Moderator / EX MS MVP Power Poster
    Join Date
    Aug 2004
    Posts
    13,490

    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
  •  





Click Here to Expand Forum to Full Width

Featured