Welcome to the Xceed Community Sign in | Join | Help
Community Search  

Re: Combobox column item display different from value

  •  04-28-2008, 3:19 PM

    Re: Combobox column item display different from value

    The main issue in this scenario is that there is no SelectedValuePath/ItemsSource equivalent for the TextBlock that is used as the CellContentTemplate. In the SolidFoundation sample, a DataTable dictionary was created to workaround this problem. The DataTableDictionary and ShipperIDDictionary classes are there for that reason. That said, add them both to your project and define you CellContentTemplate in the following manner (I have simplified the code from the SolidFoundation sample)

       <Grid xmlns:xcdg="http://schemas.xceed.com/wpf/xaml/datagrid">
          <Grid.Resources>
             <xcdg:DataGridCollectionViewSource x:Key="cvs_orders"
                                                Source="{Binding Source={x:Static Application.Current},
                                                             Path=Orders}" />
          </Grid.Resources>

          <xcdg:DataGridControl x:Name="OrdersGrid"
                                ItemsSource="{Binding Source={StaticResource cvs_orders}}">
             <xcdg:DataGridControl.Columns>
                <xcdg:Column FieldName="ShipVia">
                   <xcdg:Column.CellContentTemplate>
                      <DataTemplate>
                         <local:ShipperIDDictionary Key="{TemplateBinding Content}"
                                                    MinHeight="22">
                            <local:ShipperIDDictionary.ContentTemplate>
                               <DataTemplate>
                                  <TextBlock Text="{Binding CompanyName}" />
                               </DataTemplate>
                            </local:ShipperIDDictionary.ContentTemplate>
                         </local:ShipperIDDictionary>
                      </DataTemplate>
                   </xcdg:Column.CellContentTemplate>
                   <xcdg:Column.CellEditor>
                      <xcdg:CellEditor>
                         <xcdg:CellEditor.EditTemplate>
                            <DataTemplate>
                               <ComboBox BorderThickness="0"
                                         Background="Transparent"
                                         Foreground="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=(TextElement.Foreground)}"
                                         MinHeight="22"
                                         VerticalContentAlignment="Top"
                                         SelectedValuePath="ShipperID"
                                         ItemsSource="{Binding Source={x:Static Application.Current},Path=Shippers}"
                                         SelectedValue="{xcdg:CellEditorBinding}">
                                  <ComboBox.ItemTemplate>
                                     <DataTemplate>
                                        <TextBlock Text="{Binding Path=CompanyName}" />
                                     </DataTemplate>
                                  </ComboBox.ItemTemplate>
                                  <ComboBox.Resources>
                                     <Style TargetType="Popup">
                                        <Setter Property="TextElement.Foreground"
                                                Value="{DynamicResource {x:Static SystemColors.WindowTextBrushKey}}" />
                                     </Style>
                                  </ComboBox.Resources>
                               </ComboBox>
                            </DataTemplate>
                         </xcdg:CellEditor.EditTemplate>
                         <xcdg:CellEditor.ActivationGestures>
                            <xcdg:KeyActivationGesture SystemKey="Down"
                                                       Modifiers="Alt" />
                            <xcdg:KeyActivationGesture Key="Up"
                                                       Modifiers="Alt" />
                            <xcdg:KeyActivationGesture Key="F4" />
                            <xcdg:KeyActivationGesture Key="Space" />
                         </xcdg:CellEditor.ActivationGestures>
                      </xcdg:CellEditor>
                   </xcdg:Column.CellEditor>
                </xcdg:Column>
             </xcdg:DataGridControl.Columns>
          </xcdg:DataGridControl>
       </Grid>


    Technical Writer - Xceed Software

    Of all the things I've lost, I miss my mind the most. - Mark Twain
View Complete Thread
Contact | Site Map | Reviews | Legal Terms of Use | Trademarks | Privacy Statement Copyright 2008 Xceed Software Inc.