Hi, im using Hierarchy data that got stuck on show totals with gridviewgroup but the values always zero on childtemplate
i'm attached files with no group and it works fine. otherwise still zero if using group on childtemplate.
private void SetDataGridTemplate() { this.datagrid.Columns.Clear(); this.datagrid.GroupDescriptors.Clear(); this.datagrid.Templates.Clear(); this.datagrid.Relations.Clear(); this.datagrid.Columns.AddRange( new GridViewDecimalColumn("idsub"), new GridViewTextBoxColumn("name"), new GridViewTextBoxColumn("unit"), new GridViewDecimalColumn("price")); var child = new GridViewTemplate(); child.Columns.AddRange( new GridViewDecimalColumn("idsub"), new GridViewTextBoxColumn("itemname"), new GridViewDecimalColumn("qty"), new GridViewTextBoxColumn("satuan"), new GridViewDecimalColumn("price"), new GridViewDecimalColumn("total"), new GridViewDecimalColumn("idcategory"), new GridViewTextBoxColumn("category") ); this.datagrid.Templates.Add(child); var grupKategori = new GroupDescriptor { Format = "{0}{1}" }; grupKategori.GroupNames.Add("idcategory", ListSortDirection.Ascending); grupKategori.GroupNames.Add("category", ListSortDirection.Ascending); this.datagrid.Templates[0].GroupDescriptors.Add(grupKategori); var item1 = new GridViewSummaryItem { Name = "price", Aggregate = GridAggregateFunction.Sum, FormatString = "" }; var item2 = new GridViewSummaryItem { Name = "total", Aggregate = GridAggregateFunction.Sum, FormatString = "{0:0}" }; var rowSummary = new GridViewSummaryRowItem(new[] { item1, item2 }); this.datagrid.Templates[0].SummaryRowsBottom.Add(rowSummary); this.datagrid.Templates[0].ShowParentGroupSummaries = true; this.datagrid.Templates[0].ShowTotals = true; var relation = new GridViewRelation(); relation.ParentTemplate = this.datagrid.MasterTemplate; relation.ChildTemplate = this.datagrid.Templates[0]; relation.ParentColumnNames.Add("idsub"); relation.ChildColumnNames.Add("idsub"); this.datagrid.Relations.Add(relation); } private void buttonLoad_Click(object sender, EventArgs e) { this.SetDataGridTemplate(); this.datagrid.DataSource = GetParentSource(); this.datagrid.Templates[0].DataSource = GetChildSource(); } private void datagrid_GroupSummaryEvaluate(object sender, GroupSummaryEvaluationEventArgs e) { switch (e.SummaryItem.Name) { case "idcategory": string[] arr = e.Value.ToString().Split(new[] { ';' }, StringSplitOptions.RemoveEmptyEntries); string strvalue = e.Value.ToString(); if (strvalue.Contains(",")) { arr = e.Value.ToString().Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries); if (arr.Length > 1) { e.FormatString = arr[1]; } } break; case "total": switch (e.Parent) { case GridViewGroupRowInfo _: e.FormatString = "{0:0}"; break; case GridViewHierarchyRowInfo _: e.FormatString = "{0:0}"; break; } break; case "price": if (e.Parent is GridViewGroupRowInfo GroupRow) { e.FormatString = $"SubTotal {GroupRow.HeaderText}"; } else if (e.Parent == this.datagrid.MasterView.ViewTemplate) { e.FormatString = "Total "; } else if (e.Parent is GridViewHierarchyRowInfo h) { e.FormatString = "Total "; } break; } }