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();
}
}
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();
}
}
}
欢迎转载,转载请注明出处:http://www.cnblogs.com/Tonyyang/