I have a DataGridTemplateColumn with a Grouped combobox. The Combobox has as ItemSource a ListCollectionView with two fields: TipoBienes_ID and Bienes_ID.
What I want is simple, a combo within a datagrid column that allow me to pick one Bienes_ID but groups by TipoBienes_ID like this:
TipoBienes_ID1
Bienes_ID1
Bienes_ID2
TipoBienes_ID2
Bienes_ID3
Bienes_ID4
I have managed to view the items correctly grouped, select the one I want, but instead of the headers a light blue space appears (as it should, but without the header text). I know I have a Binding problem but cannot find it. I am sure it is a simple thing that I am missing. I am binding the datagrid in code (see below) and the combobox within the datagridtemplatecolumn with a property in the main window.
Here is my HTML code:
<DataGrid Grid.Row="1" Name="DetalleFactura" AutoGenerateColumns="False" >
<DataGrid.Columns >
<DataGridTemplateColumn x:Name="ColumnaCombo">
<DataGridTemplateColumn.CellTemplate >
<DataTemplate >
<TextBlock Text="{Binding Path=Bienes_ID}"></TextBlock>
</DataTemplate>
</DataGridTemplateColumn.CellTemplate>
<DataGridTemplateColumn.CellEditingTemplate >
<DataTemplate >
<ComboBox x:Name="ComboBienesAgrupados" SelectedValuePath="Bienes_ID" ItemsSource="{Binding Path=ListaBienes, RelativeSource={RelativeSource AncestorType=Window}}" SelectedValue="{Binding Bienes_ID}" >
<ComboBox.GroupStyle >
<GroupStyle>
<GroupStyle.HeaderTemplate >
<DataTemplate >
<TextBox Text="{Binding TipoBienes_ID}" Background ="AliceBlue" ></TextBox>
</DataTemplate>
</GroupStyle.HeaderTemplate>
</GroupStyle>
</ComboBox.GroupStyle>
<ComboBox.ItemTemplate >
<DataTemplate >
<TextBlock Text="{Binding Path=Bienes_ID}" ></TextBlock>
</DataTemplate>
</ComboBox.ItemTemplate>
</ComboBox>
</DataTemplate>
</DataGridTemplateColumn.CellEditingTemplate>
</DataGridTemplateColumn>
</DataGrid.Columns>
</DataGrid>
Here is the part that populates the datagrid and the combo:
Public Class Bien
Public Property Bienes_ID As String
Public Property TipoBienes_ID As String
End Class
Public Class Bienes
Inherits CatalogoWPF
Sub New()
MyBase.New(My.Settings.CadenaArchivo, "Select * from Bienes order by Bienes_ID", "Bienes")
End Sub
Public Property Bienes_ID As String
Get
Return ObtainField("Bienes_ID")
End Get
Set(value As String)
SetField("Bienes_ID", value)
End Set
End Property
Public Property TipoBienes_ID As String
Get
Return ObtainField("TipoBienes_ID")
End Get
Set(value As String)
SetField("TipoBienes_ID", value)
End Set
End Property
Function ObtieneListaAgrupada() As ListCollectionView
Dim Lista As New List(Of Bien)
Dim i As Integer
Dim elemento As Bien
Dim salida As ListCollectionView
Navigate(PossibleDirections.FirstItem)
For i = 0 To Count - 1
elemento = New Bien
elemento.Bienes_ID = Bienes_ID
elemento.TipoBienes_ID = TipoBienes_ID
Lista.Add(elemento)
Navigate(PossibleDirections.NextItem)
Next
salida = New ListCollectionView(Lista)
salida.GroupDescriptions.Add(New PropertyGroupDescription("TipoBienes_ID"))
Return salida
End Function
End Class
In the window where the datagrid resides, I have this code in the Loaded Event:
Public Class frmCapturaFacturas
Implements INotifyPropertyChanged
Dim m_Proveedores As Proveedores
Dim m_DetalleFacturas As DetalleFacturas
Dim m_DetalleImpuestosFacturas As DetalleImpuestosFacturas
Dim m_impuestosFacturas As DetalleImpuestosFacturas
Dim m_impuestos As ImpuestosFacturas
Dim m_marcas As Marcas
Dim m_bienes As Bienes
Dim m_tablaDetalle As DataTable
Dim m_tablabienes As DataView
Dim m_SubTotalFactura As Decimal
Dim m_SubTotalImpuestos As Decimal
Dim m_ListaBienes As ListCollectionView
Public Event PropertyChanged As PropertyChangedEventHandler Implements INotifyPropertyChanged.PropertyChanged
Public Property ListaBienes As ListCollectionView
Get
Return m_ListaBienes
End Get
Set(value As ListCollectionView)
m_ListaBienes = value
End Set
End Property
Private Sub frmCapturaFacturas_Loaded(sender As Object, e As RoutedEventArgs) Handles Me.Loaded
m_bienes = New Bienes()
ListaBienes = m_bienes.ObtieneListaAgrupada
m_bienes.Dispose()
m_DetalleFacturas = New DetalleFacturas
m_tablaDetalle = m_DetalleFacturas.CreaTabla
DetalleFactura.ItemsSource = m_tablaDetalle.DefaultView
End Sub
What I have tried:
I have replaced Text="{Binding Path=TipoBienes_ID}" with a plain Text="hello" and on every header that word appeard. Also I replaced Text="{Binding Path=TipoBienes_ID}" with Text="{Binding Path=Bienes_ID}" and the same blank space was shown.