Hello..
I have a datagrid and one of the columns is a template column with a combobox. The items in the datagrid and the combobox come from a collection. The datagrid collection has the .Include in the select statement because I don't want to show the ids but the related fields. When I click on the combobox it works fine, it does select the item I want, however, for some reason, once I click on another cell, the content dissapears... I know is there and has being selected because when I click back it shows up again.
Here is my datagrid collection:
#region gettingAllDespachos public ObservableCollection<Despacho> getAllDespachos() { var despacho = (from d in context.Despachos.Include("Cliente").Include("Ruta").Include("Employee") select d).ToList(); return new ObservableCollection<Despacho>(despacho); } #endregion
Here is where I get the collection for my combobox:
#region RutaComboBox public List<Ruta> RutasCombo { get { List<Ruta> listRuta = new List<Ruta>(); var rutas = from r in context.Rutas select r; foreach (var item in rutas) { Ruta ruta = new Ruta(); ruta.RutaID = item.RutaID; ruta.RutaDescripcion = item.RutaDescripcion; listRuta.Add(item); } return listRuta.OrderBy(r => r.RutaDescripcion).ToList(); } }
HEre is XAML code:
<!--Ruta Combobox--><DataGridTemplateColumn x:Name="rutaColumn" Header="Ruta" Width="250" SortMemberPath="RutaID"><DataGridTemplateColumn.CellTemplate><DataTemplate><TextBlock Text="{Binding Ruta.RutaDescripcion}" /><!--For some reason if I only select here the RutaID Primary Key it works!!--><!--<TextBlock Text="{Binding RutaID}" />--></DataTemplate></DataGridTemplateColumn.CellTemplate><DataGridTemplateColumn.CellEditingTemplate><DataTemplate><ComboBox x:Name="rutaComboBox" SelectedValue="{Binding RutaID, NotifyOnSourceUpdated=True,Mode=TwoWay, UpdateSourceTrigger=PropertyChanged, ValidatesOnExceptions=True}" SelectedValuePath="RutaID" DisplayMemberPath="RutaDescripcion" HorizontalContentAlignment="Stretch" ItemsSource="{Binding RutasCombo, ElementName=ListarDespachosPG}" ><ComboBox.ItemContainerStyle><Style TargetType="{x:Type ComboBoxItem}"><Setter Property="Template"><Setter.Value><ControlTemplate><Grid><Grid.ColumnDefinitions><ColumnDefinition Width="50"/><ColumnDefinition Width="*"/></Grid.ColumnDefinitions><TextBlock Margin="5" Grid.Column="0" Text="{Binding RutaID}"/><TextBlock Margin="5" Grid.Column="1" Text="{Binding RutaDescripcion}"/></Grid></ControlTemplate></Setter.Value></Setter></Style></ComboBox.ItemContainerStyle></ComboBox></DataTemplate></DataGridTemplateColumn.CellEditingTemplate></DataGridTemplateColumn>
As you can see, in the datagridtemplatecolumn.celltemplate I'm using
<TextBlock Text="{Binding Ruta.RutaDescripcion}" />
But when I use this:
<TextBlock Text="{Binding RutaID}" />
It works!! Hence, I think it has something to do with the fact that I want to show the description and not the ID....
Any help will be greatly appreciated...
Guisselle