Question : Silverlight DataGrid CellTemplate/CellEditTemplate Switch

I have a datagrid with is binding to an entity source.

I want to make it so when it's in "Edit Mode" the PartNumberID column changes from a TextBox to a ComboBox

I've been messing around with CellTemplate/CellEditTemplate with no luck so far

I need to also figure out how to bind the PartNumberID to the ComboBox properly

Any assistance would be much appreciated

Answer : Silverlight DataGrid CellTemplate/CellEditTemplate Switch

Example of using CellTemplate/CellEditTemplate in DataGrid (w/ComboBox).

<UserControl x:Class="Silverlight.Page"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:data="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls.Data"
    xmlns:src="clr-namespace:Silverlight"
    Width="400" Height="300">
    <UserControl.Resources>
        <src:CityProvider x:Key="cityProvider"/>
    </UserControl.Resources>
    <Grid x:Name="LayoutRoot" Background="White">
        <data:DataGrid x:Name="dataGrid" AutoGenerateColumns="False">
            <data:DataGrid.Columns>
                <data:DataGridTextColumn Header="Street Name" Binding="{Binding StreetName}"/>
                <data:DataGridTemplateColumn Header="City">
                    <data:DataGridTemplateColumn.CellTemplate>
                        <DataTemplate>
                            <TextBlock Text="{Binding CityInfo.CityName}" />
                        </DataTemplate>
                    </data:DataGridTemplateColumn.CellTemplate>
                    <data:DataGridTemplateColumn.CellEditingTemplate>
                        <DataTemplate>
                            <ComboBox SelectedItem="{Binding CityInfo, Mode=TwoWay}"
                                      ItemsSource="{Binding CityList, Source={StaticResource cityProvider}}"
                                      DisplayMemberPath="CityName"
                                  />
                        </DataTemplate>
                    </data:DataGridTemplateColumn.CellEditingTemplate>
                </data:DataGridTemplateColumn>
                <data:DataGridTextColumn Header="Zip Code" Binding="{Binding ZipCode}"/>
            </data:DataGrid.Columns>
        </data:DataGrid>
    </Grid>
</UserControl>

Above was from http://weblogs.asp.net/manishdalal/archive/2008/09/28/combobox-in-datagrid.aspx

HTH
Ashok
Random Solutions  
 
programming4us programming4us