• XAF 如何自定义PivotGrid单元格显示文本?


    using System;
    using System.Collections.Generic;

    using DevExpress.ExpressApp;
    using DevExpress.XtraPivotGrid;
    using DevExpress.ExpressApp.PivotGrid.Win;
    using DevExpress.ExpressApp.Model;

    namespace DXExample.Module
    {
        
    public class Q326025Controller : ViewController<ListView>
        {
            
    private const string PivotGridListEditorKey = "PivotGridListEditor";

            
    private void Q326025Controller_FieldValueDisplayText(object sender, PivotFieldDisplayTextEventArgs e)
            {
                
    string displayText = GetDisplayText(e.Field, e.Value);
                
    if (!string.IsNullOrEmpty(displayText))
                {
                    e.DisplayText 
    = displayText;
                }
            }
            
    private void Q326025Controller_CustomCellDisplayText(object sender, PivotCellDisplayTextEventArgs e)
            {
                
    string displayText = GetDisplayText(e.DataField, e.Value);
                
    if (!string.IsNullOrEmpty(displayText))
                {
                    e.DisplayText 
    = displayText;
                }
                
    if(e.Value != null)
                {
                    
    switch (int.Parse(e.Value.ToString()))
                    {
                        
    case -1:
                            e.DisplayText 
    = "正常班";
                            
    break;
                        
    case -2:
                            e.DisplayText 
    = "事假";
                            
    break;
                    }
                }
            }

            
    private PivotGridListEditor PivotGridListEditor
            {
                
    get { return View.Editor as PivotGridListEditor; }
            }

            
    protected virtual string GetDisplayText(PivotGridFieldBase field, object value)
            {
                
    if (field != null && value != null && value.GetType() == typeof(bool))
                {
                    IModelMember modelMember 
    = View.Model.ModelClass.FindMember(field.FieldName);
                    
    if (modelMember != null)
                    {
                        
    if ((bool)value)
                        {
                            
    if (!string.IsNullOrEmpty(modelMember.CaptionForTrue))
                            {
                                
    return modelMember.CaptionForTrue;
                            }
                        }
                        
    else
                        {
                            
    if (!string.IsNullOrEmpty(modelMember.CaptionForFalse))
                            {
                                
    return modelMember.CaptionForFalse;
                            }
                        }
                    }
                }
                
    return null;
            }
            
    protected override void OnViewChanging(View view)
            {
                
    base.OnViewChanging(view);
                Active.RemoveItem(PivotGridListEditorKey);
                
    if (view is ListView)
                {
                    Active[PivotGridListEditorKey] 
    = ((ListView)view).Editor is PivotGridListEditor;
                }
            }
            
    protected override void OnViewControlsCreated()
            {
                
    base.OnViewControlsCreated();
                ((PivotGridControl)(PivotGridListEditor.PivotGridControl)).CustomCellDisplayText 
    += new
        PivotCellDisplayTextEventHandler(Q326025Controller_CustomCellDisplayText);
                ((PivotGridControl)(PivotGridListEditor.PivotGridControl)).FieldValueDisplayText 
    += new
        PivotFieldDisplayTextEventHandler(Q326025Controller_FieldValueDisplayText);
            }
            
    protected override void OnDeactivated()
            {
                ((PivotGridControl)(PivotGridListEditor.PivotGridControl)).CustomCellDisplayText 
    -= new
        PivotCellDisplayTextEventHandler(Q326025Controller_CustomCellDisplayText);
                ((PivotGridControl)(PivotGridListEditor.PivotGridControl)).FieldValueDisplayText 
    -= new
        PivotFieldDisplayTextEventHandler(Q326025Controller_FieldValueDisplayText);
                
    base.OnDeactivated();
            }
        }

    } 

  • 相关阅读:
    小孩补脑 微信公众号
    学习用具汇总 微信公众号
    多带小孩去的地方 微信公众号
    PHP如何开启opcache缓存
    clip命令
    git pull push 报错 no matching host key type found. Their offer sshrsa
    生信分析 | 哲学方法论
    深入浅出Nginx实战与架构
    YCFramework版本更新:V1.0.7
    我的学习方法论
  • 原文地址:https://www.cnblogs.com/Tonyyang/p/2115226.html
Copyright © 2020-2023  润新知