C#更改CustomFieldData事件的背景颜色
我有一个PivotDataGrid,运行良好。还添加了CustomUnboundFieldData,但现在我想根据此字段中的值更改单元格的背景色 要更改颜色,我使用customCellAppearance事件。只有在我操作未绑定字段数据中的值后才会触发此事件 所以我的问题基本上是,如何改变细胞的背景。是否使用未绑定字段数据事件 下面是一段代码C#更改CustomFieldData事件的背景颜色,c#,wpf,devexpress,C#,Wpf,Devexpress,我有一个PivotDataGrid,运行良好。还添加了CustomUnboundFieldData,但现在我想根据此字段中的值更改单元格的背景色 要更改颜色,我使用customCellAppearance事件。只有在我操作未绑定字段数据中的值后才会触发此事件 所以我的问题基本上是,如何改变细胞的背景。是否使用未绑定字段数据事件 下面是一段代码 //create unbound field PivotGridField unboundField = pivot.Control.Fields.Add
//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方法 使用此方法,u可以获得源列,并根据方法得出的值更改单元格的背景颜色 下面是一段代码片段:
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网站:,您的哪一行代码负责更改颜色?功能“Control\u CustomCellAppearance”负责更改颜色。我刚才添加了这个函数。