1

I have a listview with id, name and price. Each such an item has a sublist with categories.

So "for each" Item I want to display all subitems. This is would it should look like:

Example

But I don't know how to do it. Here is my xaml code.

<ListView.View>
<GridView>
    <GridViewColumn Width="140" Header="ID" DisplayMemberBinding="{Binding ID}"/>
    <GridViewColumn Width="140" Header="Name" DisplayMemberBinding="{Binding Name}" />
    <GridViewColumn Width="300" Header="Price" DisplayMemberBinding="{Binding Price}" />
</GridView>

<!-- ??? -->
<Gridview ItemSource="{Binding Childs}">

I have to add a subgrid I think, but I don't know how.

This is my class structure

public class GroupedItem
{
    public int ID { get; set; }
    public string Name { get; set; }
    public float Price { get; set; }

    public IEnumerable<Item> Childs { get; set; }
}

Has someone an idea?

LaMiy
  • 103
  • 7

3 Answers3

3

you can do this with datagrid :

 <w:DataGrid ItemsSource={Binding Source={StaticResource GroupedItemList}}>
    <w:DataGrid.RowDetailsTemplate>
        <DataTemplate>
            <w:DataGrid ItemsSource={Binding Childs }>

            </w:DataGrid>
        </DataTemplate>
    </w:DataGrid.RowDetailsTemplate>
    <w:DataGrid.Columns>
        <w:DataGridTextColumn Header="Name" DisplayMemberBinding="{Binding Name}" />
        <w:DataGridTextColumn Header="Price" DisplayMemberBinding="{Binding Price}" />
    </w:DataGrid.Columns>

Also you can use this datagrid in codeplex it's free

WPF Extended DataGrid

Ghassen
  • 1,039
  • 12
  • 27
-1

You might want to use so-called tree-grid-view. There are really cool proprietary implementations by DevExpress and Infragistics. But also there are free soultions, descussed here

Community
  • 1
  • 1
maiksaray
  • 358
  • 2
  • 14
-1

In your listviewitem you will have to build a template with an other listview so your second listview is bind to

 public IEnumerable<Item> Childs { get; set; }
Zwan
  • 632
  • 2
  • 6
  • 23