i've been trying implement custom grouping infragistics xamdatagrid (infragistics3.wpf.datapresenter.v9.1.express), , pretty cribbed entire bit of code infragistics site. have 2 different date fields -- due date, , reminder date -- using groupbyevaluator. seemed , until tried add both fields groupbyarea.
what happens this: nested field groups according date of parent field opposed grouping of parent field. example, when drag "due date" (parent) field groupby, it'll group these records due date 4 categories -- due next year, due year, past due, , not set. perfect. when drag "reminder date" field (nested) groupby, i'll find multiple labels of same "reminder date" grouping nested under due date "past due".
i'm newbie posting so, can't post image. instead, i'll type 1 out:
past due (due date)
- not set (reminder date)
- this month (reminder date)
- not set (reminder date)
- older (reminder date)
- not set (reminder date)
- etc....
with each subsequent nested grouping, earliest due date (value of parent grouping) equal or greater greatest due date of previous grouping. appears though "past due" collection sorted due date asc, , it's iterating through each record , creating new nested group whenever there change in nested label. after 5 groupbyrecords given label of "this month", when next "not set" groupbyrecord pops new nested label created instead of continuing populate existing one.
i'm having related issue sorting, suspect entire issue hinges on. if grid has been sorted according due date, of sort functionality of other fields constrained due dates. example, sorting client name not sort client name records ascending or descending. instead, sort, sort due date first, , name.
sorry can't attach image. explained issue okay.
thanks in advance! code below:
imports system.collections.objectmodel imports infragistics.windows.datapresenter imports system.windows imports system.windows.controls partial public class manageentities public sub new() ' call required designer. initializecomponent() ' add initialization after initializecomponent() call. me.initializegroupbygrid() end sub #region "customgrouping" 'http://help.infragistics.com/help/doc/wpf/2012.2/clr4.0/html/infragisticswpf4.datapresenter.v12.2~infragistics.windows.datapresenter.igroupbyevaluator.html private sub initializegroupbygrid() each f in me.selectorgrid.fieldlayouts(0).fields if f.name = "form1duedate" orelse f.name = "form1lastreminderdate" f.settings.groupbyevaluator = new customdatetimeevaluator ' group data field dim fsd fieldsortdescription = new fieldsortdescription() fsd.field = f fsd.direction = system.componentmodel.listsortdirection.descending me.selectorgrid.fieldlayouts(0).sortedfields.add(fsd) end if next end sub #end region end class #region "customdatetimeevaluator" '//20150918 - infragistics: http://help.infragistics.com/help/doc/wpf/2013.1/clr4.0/html/infragisticswpf4.datapresenter.v13.1~infragistics.windows.datapresenter.igroupbyevaluator.html friend class customdatetimeevaluator implements igroupbyevaluator private const notset string = "not set" private const pastdue string = "past due" private const duethisyear string = "due year" private const duenextyear string = "due next year" private const remindthismonth string = "this month" private const remindlastmonth string = "last month" private const older string = "older" dim targetdate datetime = nothing public function doesgroupcontainrecord(byval groupbyrecord groupbyrecord, byval record datarecord) boolean implements igroupbyevaluator.doesgroupcontainrecord dim cellvalue object = record.getcellvalue(groupbyrecord.groupbyfield) dim desc string = groupbyrecord.description ' handle null values specially if cellvalue nothing or typeof cellvalue dbnull return desc = notset end if ' if value not date time, group them if typeof cellvalue datetime = false return true end if return desc = getdatelabel(ctype(cellvalue, datetime), groupbyrecord.groupbyfield.name) end function public function getgroupbyvalue(byval groupbyrecord groupbyrecord, byval record datarecord) object implements igroupbyevaluator.getgroupbyvalue dim cellvalue object = record.getcellvalue(groupbyrecord.groupbyfield) dim desc string = string.empty dim targetdate datetime = datetime.minvalue if cellvalue nothing or typeof cellvalue dbnull desc = notset elseif typeof cellvalue datetime targetdate = ctype(cellvalue, datetime) desc = getdatelabel(targetdate, groupbyrecord.groupbyfield.name) end if groupbyrecord.description = desc return targetdate end function public readonly property sortcomparer() system.collections.icomparer implements igroupbyevaluator.sortcomparer return nothing end end property private function getdatelabel(byval dt datetime, byval fldname string) string dim d string = notset dim comparison integer = nothing dim currentyear integer = datepart(dateinterval.year, now) '//if no date, return notset if dt.ticks = 0 return d end if '//group fieldname name if fldname.tolower = "form1duedate" '//past due includes records form 1 due date less july 1st of current year dim cddate new datetime(currentyear, 7, 1) comparison = dt.date.compareto(cddate.date) if comparison = 0 d = duethisyear elseif comparison < 0 d = pastdue elseif comparison > 0 d = duenextyear else d = notset end if elseif fldname.tolower = "form1lastreminderdate" dim currentmonth integer = datepart(dateinterval.month, now) dim olderthandate new datetime(currentyear, currentmonth - 1, 1) if dt.date.year = currentyear andalso dt.date.month = currentmonth d = remindthismonth elseif dt.date.year = currentyear andalso dt.date.month = currentmonth - 1 d = remindlastmonth elseif dt.date < olderthandate d = older else d = notset end if end if return d end function end class #end region
Comments
Post a Comment