tags:

views:

880

answers:

4

Hello,

I've a ListView with about 10 GridViewColumn's and about 100 Lines/Row. I'd like to display a "Total" or summary row at the bottom of the ListView.

Does anyone have a idea how to do that, with keeping the ColumnWidth etc. like the others and making it a seperate item, so the "main" ListView can have a scrollbar?

I've uploaded here a mock-up (sorry for my bad graphic talent :-)):
image

Thanks for any input!

Cheers

A: 

VirtualizingStackPanel

SUMMARY:Displaying large sets of data can be challenging to do performantly. If you have a scrolling list of data, one technique to improve performance is to only create the UI elements that are visible. This is refered to as UI virtualization (as opposed to data virtualization, which is the technique of not materializing the data that isn’t visible). WPF has a built in virtualizing panel called VirtualizingStackPanel

adatapost
Could you give me a short example how I could use a VirtualizingStackPanel for doing this? I've bound the (Main)ListView to a ItemsSource=List<ItemsViewModel> x; the last row (which contains the calculated total integers) is in a seperate variable ItemsViewModel y;
Joseph Melettukunnel
This doesn't answer the question. He didn't ask how to automatically create visual elements as he scrolls. He asked how to show something different for the last row.
Anderson Imes
A: 

It almost seems like what you want is a second listview below the first one, with some way of keeping the column sizes in sync. Is there an event you can hook to let you know that the user has resized a particular column? (I'm not really a WPF person, but WinForms offers a ColumnSizeChanged and ColumnSizeChanging event.) It's a little gross, but unless you essentially roll your own custom listview control, I don't know if you're going to do much better.

twon33
Exactly, that's what I'm looking for.. thanks for the input, I think there isn't an "easier"/cleaner way (e.g. without Code-Behind/using seperate Events).
Joseph Melettukunnel
A: 

If your data source is a StaticResource, you can use a composite collection. I really wish this would work elsewhere. Sad, really. Anyway it's really nice if you can use it.

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

Enjoy!

Anderson Imes
A: 

This is an example on how to have a listview with totals area at the end. The column width are binded between each column and its total

 <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>
federubin