c# - how to handle group subtotal and e.g. target rows in WPF DataGrid? -


i'm implementing wpf datagrid contains projects many key figures. projects grouped project categories.

for each category there should be:

  1. a row shows in each key figure column sum of rows column.
  2. a target row not part of datasource grid in binded to. target row tells every column target year (e.g. how money there's spend).

these rows should on top in each group (sorting filtering).

my 1st solution have data in group header. not solution because group header not support columns. i.e. should constructed getting column widths.

that done gets complicated when users want reorder , hide columns.

datagrid using collectionviewsource it's not populated c# code. i'm extending example: http://msdn.microsoft.com/en-us/library/ff407126.aspx

thanks & best regards - matti

i have hacked-together datagrid group subtotal rows in 1 of projects. weren't concerned of issues bring up, such hiding , sorting columns don't know sure if can extended that. realize there performance issues may problem large sets (my window operating 32 separate datagrids - ouch). it's different direction other solutions i've seen, thought i'd throw here , see if helps out.

my solution consists of 2 major components:
1. subtotal rows aren't rows in main datagrid, separate datagrids. have 2 grids in each group actually: 1 in header displayed when group collapsed, , 1 beneath itemspresenter. itemssource subtotal datagrids comes converter takes items in group , returns aggregate view model. columns of subtotal grids same main grid (filled out in datagrid_loaded, though i'm sure done in xaml too).

            <groupstyle>                 <groupstyle.containerstyle>                     <style targettype="{x:type groupitem}">                         <setter property="template">                             <setter.value>                                 <controltemplate targettype="{x:type groupitem}">                                     <expander background="gray" horizontalalignment="left" isexpanded="true"                                               scrollviewer.cancontentscroll="true">                                         <expander.header>                                             <datagrid name="headergrid" itemssource="{binding path=., converter={staticresource sumconverter}}"                                                         loaded="datagrid_loaded" headersvisibility="row"                                                         margin="25 0 0 0" previewmousedown="headergrid_previewmousedown">                                                 <datagrid.style>                                                     <style targettype="datagrid">                                                         <style.triggers>                                                             <datatrigger binding="{binding relativesource={relativesource ancestortype=expander}, path=isexpanded}"                                                                             value="true">                                                                 <setter property="visibility" value="collapsed"/>                                                             </datatrigger>                                                         </style.triggers>                                                     </style>                                                 </datagrid.style>                                             </datagrid>                                         </expander.header>                                         <stackpanel>                                             <itemspresenter/>                                             <datagrid name="footergrid" itemssource="{binding elementname=headergrid, path=itemssource, mode=oneway}"                                                             loaded="datagrid_loaded" headersvisibility="row"                                                             margin="50 0 0 0">                                                 <datagrid.style>                                                     <style targettype="datagrid">                                                         <style.triggers>                                                             <datatrigger binding="{binding relativesource={relativesource ancestortype=expander}, path=isexpanded}"                                                                          value="false">                                                                 <setter property="visibility" value="collapsed"/>                                                             </datatrigger>                                                         </style.triggers>                                                     </style>                                             </datagrid>                                         </stackpanel>                                     </expander>                                 </controltemplate>                             </setter.value>                         </setter>                     </style>                 </groupstyle.containerstyle>             </groupstyle> 


2. issue how datagrids behave if single grid. i've handled subclassing datagridtextcolumn (we have text in case, other column types should work too) in class called datagridsharedsizetextcolumn mimics sharedsizegroup behavior of grid class. has string dependency property group name , keeps track of columns in same group. when width.desiredvalue changes in 1 column, update minwidth in other columns , force update datagridowner.updatelayout(). class covering column reordering , group-wide update whenever displayindex changes. think method work other column property long has setter.

there other annoying things work out selection, copying, etc. turned out pretty easy handle mouseentered , mouseleave events , using custom copy command.


Comments

Popular posts from this blog

ios - MKAnnotationView layer is not of expected type: MKLayer -

ZeroMQ on Windows, with Qt Creator -

unity3d - Unity SceneManager.LoadScene quits application -