.NET 學習

.NET 學習生活感想... 万事成蹉跎..... 贵在坚持 及时整理自己做过和学过的东西

博客园 首页 新随笔 联系 订阅 管理

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 { getset; }
    }

    
public interface IModelColumnExtenderForGroupFooter 
    {
        [DefaultValue(SummaryItemType.None)]
        SummaryItemType GroupFooterSummaryType { 
getset; }
    }

    
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>();
        }
    }


}

 

 

 

posted on 2010-07-15 13:26  Tonyyang  阅读(640)  评论(0编辑  收藏  举报
欢迎转载,转载请注明出处:http://www.cnblogs.com/Tonyyang/