Geeks With Blogs

News
Microsoft MVP

INETA Community Champions

Join the Movement: Stop Diabetes

Illuminate Every difficult problem can be broken down into simple solutions

My problem was that using a DataGridComboBoxColumn I couldn’t get it to show the selected value when the DataGrid loaded.  Instead, the user would have to click in the cells and like magic, the current selected values would appear and it looked the way I wanted it to on load.

Here is what I had

<DataGridComboBoxColumn MinWidth="150" x:Name="crewColumn" Header="Crew" 
     ItemsSource="{Binding JobEdit.Crews, Source={StaticResource Locator}}"  
     DisplayMemberPath="Name" 
     SelectedItemBinding="{Binding JobEdit.SelectedCrew, Mode=TwoWay, Source={StaticResource Locator}}" 
 />

 

Here is what I changed it too.  This works great.  It displays the selected item when the DataGrid loads and shows the combo box when the user goes into edit mode.

 

                           <DataGridTemplateColumn Header="Crew" MinWidth="150">
                                       <DataGridTemplateColumn.CellTemplate>
                                           <DataTemplate>
                                                <TextBlock Text="{Binding Crew.Name}"></TextBlock>
                                            </DataTemplate>
                                        </DataGridTemplateColumn.CellTemplate>
                                        <DataGridTemplateColumn.CellEditingTemplate>
                                            <DataTemplate>
                                                <ComboBox ItemsSource="{Binding JobEdit.Crews, Source={StaticResource Locator}}"  
                                                   DisplayMemberPath="Name" SelectedItem="{Binding JobEdit.SelectedCrew, Mode=TwoWay, 
                                                   Source={StaticResource Locator}}"></ComboBox>
                                            </DataTemplate>
                                        </DataGridTemplateColumn.CellEditingTemplate>
                                    </DataGridTemplateColumn>
Posted on Wednesday, November 28, 2012 7:43 AM | Back to top


Comments on this post: WPF DataGrid using a DataGridTemplateColumn rather than a DataGridComboBoxColumn to show selected value at load

Comments are closed.
Comments have been closed on this topic.
Copyright © T | Powered by: GeeksWithBlogs.net | Join free