C # / WPF: Idea how to display last row of ListView separately?

I have a ListView with about 10 GridViewColumn and about 100 rows / rows. I would like to display โ€œTotalโ€ or the resulting row at the bottom of the ListView.

Does anyone have an idea how to do this by keeping ColumnWidth etc. like the others and making it a separate item, so can the "main" ListView have a scrollbar?

I downloaded the layout here (sorry for my bad graphic talent :-)):
image

+4
source share
4 answers

This is an example of how to have a list with a totals area at the end. The column width is tied between each column and the total value

<Window x:Class="WpfApplication2.Window1" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:sys="clr-namespace:System;assembly=mscorlib" Title="Window1" x:Name="ctl" Height="300" Width="300"> <Window.Resources> <GridViewColumnCollection x:Key="gvcc"> <GridViewColumn Width="{Binding Path=ActualWidth, ElementName=col1}" Header="Date" /> <GridViewColumn Width="{Binding Path=ActualWidth, ElementName=col2}" Header="Day Of Week" DisplayMemberBinding="{Binding DayOfWeek}" /> <GridViewColumn Width="{Binding Path=ActualWidth, ElementName=col3}" Header="Year" DisplayMemberBinding="{Binding Year}" /> </GridViewColumnCollection> </Window.Resources> <Grid> <DockPanel HorizontalAlignment="Stretch" VerticalAlignment="Stretch" LastChildFill="True"> <GridViewRowPresenter Name="listview_total" DockPanel.Dock="Bottom" Margin="0,5,0,5" Columns="{StaticResource gvcc}"> <GridViewRowPresenter.Content> <sys:DateTime>2005/2/1</sys:DateTime> </GridViewRowPresenter.Content> </GridViewRowPresenter> <ListView x:Name="listview_rows" SelectionMode="Single" DockPanel.Dock="Top" ScrollViewer.HorizontalScrollBarVisibility="Disabled"> <ListView.View> <GridView> <GridViewColumn x:Name="col1" Header="Date" /> <GridViewColumn x:Name="col2" Header="Day Of Week" DisplayMemberBinding="{Binding DayOfWeek}" /> <GridViewColumn x:Name="col3" Header="Year" DisplayMemberBinding="{Binding Year}" /> </GridView> </ListView.View> <sys:DateTime>1/2/3</sys:DateTime> <sys:DateTime>4/5/6</sys:DateTime> <sys:DateTime>7/8/9</sys:DateTime> <sys:DateTime>10/11/12</sys:DateTime> <sys:DateTime>1/2/3</sys:DateTime> <sys:DateTime>4/5/6</sys:DateTime> <sys:DateTime>7/8/9</sys:DateTime> <sys:DateTime>10/11/12</sys:DateTime> <sys:DateTime>1/2/3</sys:DateTime> <sys:DateTime>4/5/6</sys:DateTime> <sys:DateTime>7/8/9</sys:DateTime> <sys:DateTime>10/11/12</sys:DateTime> <sys:DateTime>1/2/3</sys:DateTime> <sys:DateTime>4/5/6</sys:DateTime> <sys:DateTime>7/8/9</sys:DateTime> <sys:DateTime>10/11/12</sys:DateTime> </ListView> </DockPanel> </Grid> </Window> 
+6
source

If the data source is StaticResource, you can use a composite collection. I really want this to work elsewhere. Itโ€™s sad, really. In any case, it is very nice if you can use it.

 <ListView> <ListView.ItemsSource> <CompositeCollection> <CollectionContainer Collection="{StaticResource MyCollection} /> <ListViewItem>Last Item</ListViewItem> </CompositeCollection> </ListView.ItemsSource> </ListView> 

Enjoy it!

+1
source

It looks like you want this second list below the first, with some way to keep the column sizes in sync. Is there an event that you can hook up to indicate that the user has resized a specific column? (I'm not really a WPF person, but WinForms offers the ColumnSizeChanged and ColumnSizeChanging event.) This is a little rude, but if you essentially don't collapse your own listview control, I don't know if you will do much better.

0
source

Creating a great federubin answer , you can bind the GridViewRowPresenter Columns property directly to the Columns GridView property.

 <GridViewRowPresenter Columns="{Binding ElementName=ListViewGridViewName, Path=Columns}" ...> 

Column widths will be automatically updated in the presenter when they are changed in the main grid, and you will no longer have to duplicate the column definitions.

 <Window x:Class="WpfTestbed.MainWindow" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:sys="clr-namespace:System;assembly=mscorlib"> <Grid> <DockPanel HorizontalAlignment="Stretch" VerticalAlignment="Stretch" LastChildFill="True"> <GridViewRowPresenter Columns="{Binding ElementName=ListViewGridView, Path=Columns}" DockPanel.Dock="Bottom" Margin="4,5,0,5"> <GridViewRowPresenter.Content> <sys:DateTime>2005/2/1</sys:DateTime> </GridViewRowPresenter.Content> </GridViewRowPresenter> <ListView SelectionMode="Single" ScrollViewer.HorizontalScrollBarVisibility="Disabled"> <ListView.View> <GridView x:Name="ListViewGridView"> <GridViewColumn Header="Date" /> <GridViewColumn Header="Day Of Week" DisplayMemberBinding="{Binding DayOfWeek}" /> <GridViewColumn Header="Year" DisplayMemberBinding="{Binding Year}" /> </GridView> </ListView.View> <sys:DateTime>1/2/3</sys:DateTime> <sys:DateTime>4/5/6</sys:DateTime> <sys:DateTime>7/8/9</sys:DateTime> <sys:DateTime>10/11/12</sys:DateTime> <sys:DateTime>1/2/3</sys:DateTime> <sys:DateTime>4/5/6</sys:DateTime> <sys:DateTime>7/8/9</sys:DateTime> <sys:DateTime>10/11/12</sys:DateTime> <sys:DateTime>1/2/3</sys:DateTime> <sys:DateTime>4/5/6</sys:DateTime> <sys:DateTime>7/8/9</sys:DateTime> <sys:DateTime>10/11/12</sys:DateTime> <sys:DateTime>1/2/3</sys:DateTime> <sys:DateTime>4/5/6</sys:DateTime> <sys:DateTime>7/8/9</sys:DateTime> <sys:DateTime>10/11/12</sys:DateTime> </ListView> </DockPanel> </Grid> </Window> 
0
source

All Articles