'Can I create a DataGrid of an object containing a List<KeyValuePair> in horizontal view?
I have a list of items which I want to present in a datagrid. But each item contains a list of KeyValuePairs which I want to view horizontally. Is there any way?
The object I want to present:
public class ItemModel
{
public string Model { get; set; }
public List<KeyValuePair<string, int>> DetailsList { get; set; }
}
My xaml looks like this, but it returns a datagrid with Key and Value as columns instead of Key1, Key2, Key3 etc as columns:
<DataGrid x:Name="PurchaseOrder" CanUserAddRows="False" AutoGenerateColumns="False" CellEditEnding="PurchaseOrder_CellEditEnding">
<DataGrid.Columns>
<DataGridTextColumn Header="Model" Binding="{Binding Path=Model}" />
<DataGridTemplateColumn Header="">
<DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<StackPanel Orientation="Horizontal">
<DataGrid ItemsSource="{Binding DetailsList}" CanUserAddRows="False"
AutoGenerateColumns="True" CellEditEnding="Models_CellEditEnding">
</DataGrid>
</StackPanel>
</DataTemplate>
</DataGridTemplateColumn.CellTemplate>
</DataGridTemplateColumn>
</DataGrid.Columns>
</DataGrid>
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
