[英]C# Changing background color of an CustomFieldData event
I've got an PivotDataGrid wich is working fine. 我有一个PivotDataGrid,它工作正常。 Also added an CustomUnboundFieldData, but now i want to change the backgroundcolor of the cell according to the value in this field. 还添加了CustomUnboundFieldData,但现在我想根据此字段中的值更改单元格的背景色。
To change the color i use a customCellAppearance event. 要更改颜色,我使用customCellAppearance事件。 Only this event is fired after i manipulate the values in the unbound field data. 我操纵未绑定字段数据中的值后,只会触发此事件。
So my question basically is, how to change the background of a cell. 所以我的问题基本上是,如何改变细胞的背景。 Using the unbound field data event? 使用未绑定的字段数据事件?
Below a snippet of the code 下面的代码片段
//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;
}
}
To change the color according to the "original data", use the CreateDrillDownDataSource method. 要根据“原始数据”更改颜色,请使用CreateDrillDownDataSource方法。
With this method u can get the source column and change the background color of the cell according to the value that comes out of the method. 使用此方法,您可以获取源列,并根据该方法中产生的值更改单元格的背景色。
Below a code snippet: 下面的代码段:
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;
}
}
For more information i refer to the devexpress website: http://documentation.devexpress.com/#WindowsForms/DevExpressXtraPivotGridPivotCellBaseEventArgs_CreateDrillDownDataSourcetopic 有关更多信息,请访问devexpress网站: http ://documentation.devexpress.com/#WindowsForms/DevExpressXtraPivotGridPivotCellBaseEventArgs_CreateDrillDownDataSourceTop
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.