how to display a group footer for List Views
官方资料:http://documentation.devexpress.com/#Xaf/CustomDocument2785
using System;
using System.ComponentModel;
using System.Collections.Generic;
using System.Diagnostics;
using System.Text;
using DevExpress.ExpressApp;
using DevExpress.ExpressApp.Actions;
using DevExpress.Persistent.Base;
using DevExpress.ExpressApp.Model;
using DevExpress.Data;
using DevExpress.ExpressApp.Win.Editors;
using DevExpress.XtraGrid.Views.Grid;
using DevExpress.XtraGrid.Columns;
namespace XafExtendTest.Module.SystemModule
{
public interface IModelListVewGroupFooterVisible : IModelNode
{
bool IsGroupFooterVisible { get; set; }
}
public interface IModelColumnExtenderForGroupFooter
{
[DefaultValue(SummaryItemType.None)]
SummaryItemType GroupFooterSummaryType { get; set; }
}
public class GroupFooterVisibleListViewController : ViewController<ListView>,IModelExtender
{
private void View_InfoSynchronized(object sender, EventArgs e)
{
IModelListVewGroupFooterVisible modelListView = View.Model as IModelListVewGroupFooterVisible;
if (modelListView != null && modelListView.IsGroupFooterVisible)
{
GridListEditor gridListEditor = View.Editor as GridListEditor;
if (gridListEditor != null)
{
GridView gridView = gridListEditor.GridView;
for (int i = 0; i < gridView.GroupSummary.Count; i++)
{
IModelColumnExtenderForGroupFooter modelColumn = View.Model.Columns[
gridView.GroupSummary[i].FieldName] as IModelColumnExtenderForGroupFooter;
if (modelColumn != null)
{
modelColumn.GroupFooterSummaryType = gridView.GroupSummary[i].SummaryType;
}
}
}
}
}
protected override void OnViewControlsCreated()
{
base.OnViewControlsCreated();
IModelListVewGroupFooterVisible modelListView = View.Model as IModelListVewGroupFooterVisible;
if (modelListView != null && modelListView.IsGroupFooterVisible)
{
GridListEditor gridListEditor = View.Editor as GridListEditor;
if (gridListEditor != null)
{
GridView gridView = gridListEditor.GridView;
gridView.GroupFooterShowMode = GroupFooterShowMode.VisibleAlways;
foreach (IModelColumn modelColumn in View.Model.Columns)
{
IModelColumnExtenderForGroupFooter modelColumnExtender = modelColumn as IModelColumnExtenderForGroupFooter;
if (modelColumnExtender != null &&
modelColumnExtender.GroupFooterSummaryType != SummaryItemType.None)
{
GridColumn gridColumn = gridView.Columns[
modelColumn.ModelMember.MemberInfo.BindingName];
gridView.GroupSummary.Add(modelColumnExtender.GroupFooterSummaryType,
modelColumn.Id, gridColumn);
}
}
}
}
}
protected override void OnActivated()
{
base.OnActivated();
View.InfoSynchronized += View_InfoSynchronized;
}
protected override void OnDeactivated()
{
View.InfoSynchronized -= View_InfoSynchronized;
base.OnDeactivated();
}
void IModelExtender.ExtendModelInterfaces(ModelInterfaceExtenders extenders)
{
extenders.Add<IModelListView, IModelListVewGroupFooterVisible>();
extenders.Add<IModelColumn, IModelColumnExtenderForGroupFooter>();
}
}
}
using System.ComponentModel;
using System.Collections.Generic;
using System.Diagnostics;
using System.Text;
using DevExpress.ExpressApp;
using DevExpress.ExpressApp.Actions;
using DevExpress.Persistent.Base;
using DevExpress.ExpressApp.Model;
using DevExpress.Data;
using DevExpress.ExpressApp.Win.Editors;
using DevExpress.XtraGrid.Views.Grid;
using DevExpress.XtraGrid.Columns;
namespace XafExtendTest.Module.SystemModule
{
public interface IModelListVewGroupFooterVisible : IModelNode
{
bool IsGroupFooterVisible { get; set; }
}
public interface IModelColumnExtenderForGroupFooter
{
[DefaultValue(SummaryItemType.None)]
SummaryItemType GroupFooterSummaryType { get; set; }
}
public class GroupFooterVisibleListViewController : ViewController<ListView>,IModelExtender
{
private void View_InfoSynchronized(object sender, EventArgs e)
{
IModelListVewGroupFooterVisible modelListView = View.Model as IModelListVewGroupFooterVisible;
if (modelListView != null && modelListView.IsGroupFooterVisible)
{
GridListEditor gridListEditor = View.Editor as GridListEditor;
if (gridListEditor != null)
{
GridView gridView = gridListEditor.GridView;
for (int i = 0; i < gridView.GroupSummary.Count; i++)
{
IModelColumnExtenderForGroupFooter modelColumn = View.Model.Columns[
gridView.GroupSummary[i].FieldName] as IModelColumnExtenderForGroupFooter;
if (modelColumn != null)
{
modelColumn.GroupFooterSummaryType = gridView.GroupSummary[i].SummaryType;
}
}
}
}
}
protected override void OnViewControlsCreated()
{
base.OnViewControlsCreated();
IModelListVewGroupFooterVisible modelListView = View.Model as IModelListVewGroupFooterVisible;
if (modelListView != null && modelListView.IsGroupFooterVisible)
{
GridListEditor gridListEditor = View.Editor as GridListEditor;
if (gridListEditor != null)
{
GridView gridView = gridListEditor.GridView;
gridView.GroupFooterShowMode = GroupFooterShowMode.VisibleAlways;
foreach (IModelColumn modelColumn in View.Model.Columns)
{
IModelColumnExtenderForGroupFooter modelColumnExtender = modelColumn as IModelColumnExtenderForGroupFooter;
if (modelColumnExtender != null &&
modelColumnExtender.GroupFooterSummaryType != SummaryItemType.None)
{
GridColumn gridColumn = gridView.Columns[
modelColumn.ModelMember.MemberInfo.BindingName];
gridView.GroupSummary.Add(modelColumnExtender.GroupFooterSummaryType,
modelColumn.Id, gridColumn);
}
}
}
}
}
protected override void OnActivated()
{
base.OnActivated();
View.InfoSynchronized += View_InfoSynchronized;
}
protected override void OnDeactivated()
{
View.InfoSynchronized -= View_InfoSynchronized;
base.OnDeactivated();
}
void IModelExtender.ExtendModelInterfaces(ModelInterfaceExtenders extenders)
{
extenders.Add<IModelListView, IModelListVewGroupFooterVisible>();
extenders.Add<IModelColumn, IModelColumnExtenderForGroupFooter>();
}
}
}
欢迎转载,转载请注明出处:http://www.cnblogs.com/Tonyyang/