更改CustomFieldData事件的背景颜色
本文关键字:背景 颜色 事件 CustomFieldData 更改 | 更新日期: 2023-09-27 18:18:53
我有一个PivotDataGrid,它工作得很好。还添加了一个CustomUnboundFieldData,但现在我想根据这个字段的值改变单元格的背景颜色。
要改变颜色,我使用customCellAppearance事件。只有在我操作未绑定字段数据中的值后才触发此事件。
我的问题是,如何改变一个单元格的背景。使用未绑定字段数据事件?
在一段代码
下面//create unbound field
PivotGridField unboundField = pivot.Control.Fields.Add("unboundDataField", FieldArea.FilterArea);
unboundField.UnboundType = FieldUnboundColumnType.String;
//fill unbound field with data
private void Control_CustomUnboundFieldData(object sender, PivotCustomFieldDataEventArgs e)
{
String myValue = Convert.ToString(e.GetListSourceColumnValue("sourceColumn"));
e.Value = myValue.Substring(6);
e.Field.SummaryType = FieldSummaryType.Max;
}
//code to change appearance of different cells
private void Control_CustomCellAppearance(object sender, PivotCustomCellAppearanceEventArgs e)
{
if(e.Value != null)
{
e.Background = System.Windows.Media.Brushes.Green;
}
}
要根据"原始数据"改变颜色,使用CreateDrillDownDataSource方法。
使用此方法,您可以获得源列并根据该方法产生的值更改单元格的背景颜色。
代码段下面:
private void Control_CustomCellAppearance(object sender, PivotCustomCellAppearanceEventArgs e)
{
PivotDrillDownDataSource ds = e.CreateDrillDownDataSource();
//get value from the original source according to the row index
String myValue = Convert.ToString(ds.GetValue(e.RowIndex, "sourceColumn"));
//backgroundcolor condition
if(myValue.Containts("something"))
{
e.Background = System.Windows.Media.Brushes.Green;
}
}
更多信息请参考devexpress网站:http://documentation.devexpress.com/#WindowsForms/DevExpressXtraPivotGridPivotCellBaseEventArgs_CreateDrillDownDataSourcetopic