Hi, I need change captions in PivotChart for a Boolean value.
How can I do it? I try to do it with CaptionsForBoolValues without success.
Attach image to show what I mean.
Thanks in advance
ALBERTO
PivotGrid module - CaptionForTrue and CaptionForFalse are not taken into account when displaying field values
Answers
Hello Alberto,
Currently, you should manually change these captions in ViewController using the PivotGridControl.FieldValueDisplayText and PivotGridControl.CustomCellDisplayText events, as shown below:
C#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;
}
}
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();
}
}
We are going to fix this issue in the next XAF versions. I have converted your question to a bug report.
Thanks,
Anatol