wpf - Getting a group total in DataGrid -
i'll seek create simple possible, have been working on 3 days , have tried many different options reason still cannot work. i'm new wpf , matter vb.net.
so have datagrid has grouping, multiple levels. code below.
this usercontrol.resources section:
<collectionviewsource x:key="hoursviewsource"> <collectionviewsource.groupdescriptions> <propertygroupdescription propertyname="phase"/> <propertygroupdescription propertyname="employee"/> </collectionviewsource.groupdescriptions> </collectionviewsource> <local:grouptotalconverter x:key="grouptotal"/>
and datagrid: have sec groupstyle below 1 on same datagrid, not of import question.
<datagrid grid.row="1" grid.columnspan="2" itemssource="{binding mode=oneway}" isreadonly="true" autogeneratecolumns="false"> <datagrid.columns> <datagridtextcolumn width="80" header="date" binding="{binding transdate, stringformat=d}"/> <datagridtextcolumn width="80" header="period" binding="{binding period}"/> <datagridtextcolumn width="80" header="hours" binding="{binding hours, stringformat=n}"/> <datagridtextcolumn width="200" header="comment" binding="{binding transcomment, stringformat=n}"/> </datagrid.columns> <datagrid.groupstyle> <groupstyle> <groupstyle.containerstyle> <style targettype="{x:type groupitem}"> <setter property="template"> <setter.value> <controltemplate> <expander foreground="white" margin="0,0,0,3"> <expander.header> <dockpanel> <textblock text="{binding path=name}"/> <textblock text="{binding path=items, converter={staticresource grouptotal}"/> </dockpanel> </expander.header> <expander.content> <itemspresenter> <itemspresenter.effect> <dropshadoweffect/> </itemspresenter.effect> </itemspresenter> </expander.content> </expander> </controltemplate> </setter.value> </setter> </style> </groupstyle.containerstyle> </groupstyle> </datagrid.groupstyle> </datagrid>
as can see have converter gets passed items group, have been checking items passed , working correctly. problem in converter, or @ to the lowest degree that's assumption have been going on. when @ collection of items gets passed there properties beingness sent datagrid. cannot info sent converter.
converter:
public function convert(value object, targettype type, parameter object, civilization cultureinfo) object implements ivalueconverter.convert if typeof value readonlyobservablecollection(of object) dim items = ctype(value, readonlyobservablecollection(of object)) dim total decimal = 0 each gi groupitem in items total += gi.hours next gi homecoming total.tostring() end if homecoming ""
so converter conversion c#, found in question. cannot cast same type of object original, although done major modifications underlying datagrid source. have tried casting simple class has properties of collection passed converter errors , says item "hours" in case not part of collectiongroupviewinternal when stepping through code , looking @ collection there property hours = .
i hope made issue clear, tells me super easy fix, stubborn nature required spend way many hours on this.
what i'm hoping create converter can utilize on , on total of specific columns , place in textblock of header of group. current project i'm working on have dozens of these datagrids groupings.
thank help in advance.
isn't how goes, inquire help figure out.
well post solution found , how came it. i'm not sure if best solution, work.
so working debugger, realized sending converter collection of collections. sort of. sending readonlyobservablecollection, collection had 1 thing, collection of collectionviewgroupinternal derives collectionviewgroup, collection had items wanted included in total amount.
so here converter: hope help someone.
public function convert(value object, targettype type, parameter object, civilization cultureinfo) object implements ivalueconverter.convert if typeof value readonlyobservablecollection(of object) each r in value dim items collectionviewgroup = ctype(r, collectionviewgroup) dim total decimal = 0 each item in items.items total += item.hours next homecoming total next end if homecoming "" end function
if see way improve grateful.
wpf vb.net wpfdatagrid
No comments:
Post a Comment