Binding Combobox to display integer values

I Bind a ComboBox to an Entity. I want the Combobox to display on each Item multiple values of different format (Integer, String and DateTime values), like this:

Item#1) 100  - Description - 01/01/2013

Item#2) 101  - Description - 01/01/2013

But the ComboBox only displays the SQL char (C# string) values, the others are empty:

Item#1)     - Description -

Item#2)     - Description - 

I have to use a Converter, am I on the wrong path, or there is a simpler solution?

In XAML

 <UserControl.Resources>
    <CollectionViewSource x:Key="tSCHEDEViewSource" d:DesignSource="{d:DesignInstance my:TSCHEDE, CreateList=True}" />
    <DataTemplate x:Key="SchedaTemplate">
        <StackPanel Orientation="Horizontal">
            <TextBlock Text="{Binding Path=KSCHEDA}" Width="60"></TextBlock>
            <TextBlock Text="{Binding Path=DArticolo}" Width="200"></TextBlock>
            <TextBlock Text=" - " Width="40"></TextBlock>
            <TextBlock Text="{Binding Path=DStorico}" Width="150"></TextBlock>
        </StackPanel>
    </DataTemplate>
</UserControl.Resources>

<ComboBox ItemTemplate="{StaticResource SchedaTemplate}" Grid.Column="1" Grid.Row="1" Height="23"   HorizontalAlignment="Left" ItemsSource="{Binding}" Margin="23,129,0,0" Name="tSCHEDEComboBox1" SelectedValuePath="KScheda" VerticalAlignment="Top" Width="393">
        <ComboBox.ItemsPanel>
            <ItemsPanelTemplate>
                <VirtualizingStackPanel />
            </ItemsPanelTemplate>
        </ComboBox.ItemsPanel>
    </ComboBox>

The .edmx Model

<EntityType Name="TSCHEDE">
      <Key>
        <PropertyRef Name="KSCHEDA" />
      </Key>
      <Property Name="KSCHEDA" Type="int" Nullable="false" />
      <Property Name="KLINEA" Type="int" Nullable="false" />
      <Property Name="DSCHEDA" Type="char" MaxLength="30" />
      <Property Name="DSTORICO" Type="datetime" />
      <Property Name="FINSMAN" Type="char" MaxLength="1" />
      <Property Name="DNOTE" Type="char" MaxLength="255" />
      <Property Name="FCANC" Type="char" MaxLength="1" />
      <Property Name="DArticolo" Type="char" MaxLength="60" />
      <Property Name="FFIGLIA" Type="char" MaxLength="1" />
    </EntityType>

Answers


I think that you have problem with case sensitive. When you binding you must exactly rewrite name of the variable.

Try this:

<UserControl.Resources>
    <CollectionViewSource x:Key="tSCHEDEViewSource" d:DesignSource="{d:DesignInstance my:TSCHEDE, CreateList=True}" />
    <DataTemplate x:Key="SchedaTemplate">
        <StackPanel Orientation="Horizontal">
            <TextBlock Text="{Binding Path=KSCHEDA}" Width="60"></TextBlock>
            <TextBlock Text="{Binding Path=DARTICOLO" Width="200"></TextBlock>
            <TextBlock Text=" - " Width="40"></TextBlock>
            <TextBlock Text="{Binding Path=DSTORICO}" Width="150"></TextBlock>
        </StackPanel>
    </DataTemplate>
</UserControl.Resources>

In SelectedValuePath you also have wrong variable, change it to SelectedValuePath="KSCHEDA".


Need Your Help

How do I calm down this hyper event listener

c# silverlight silverlight-3.0 event-handling slider

I have a simple silverlight toolkit Chart and a standard Slider in the same control. I want the Chart to be updated whenever the slider value changes. This oughta be simple. I tried binding to the

Qt UI testing: How to simulate a click on a QMenuBar item using QTest?

c++ qt qmenu qtestlib

I am trying to simulate a mouse click on a QMenu item from a QMenuBar, for example clicking on "Save As" QAction using the QTestLib framework.

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.