0
我的情況是,我需要繪製綠色編輯的透視網格中的單元格。我試圖訂閱pivot網格到CustomCellAppearance
事件,但是當然這會繪製整個數據表。我使用LostFocus
事件處理編輯部分,這意味着單元格在失去焦點時會被編輯。在這種情況下,我需要繪製單元格。如何更改透視網格中編輯的單元格的顏色DevExpress
這是一段我PivotGridView.xaml代碼(其中樞紐電網的定義):
<dxpg:PivotGridControl x:Name="PivotGridControl1" ChartSelectionOnly="False"
CellSelectedBackground="LightSlateGray" CellBackground="GhostWhite" Background="LightBlue"
ValueSelectedBackground="LightSlateGray"
CellTotalBackground="Linen" ValueTotalBackground="LightSkyBlue" ValueBackground="LightSteelBlue"
ValueTotalSelectedBackground="DeepSkyBlue"
Width="Auto" Height="430" Margin="0,-1,-8,40">
<dxpg:PivotGridControl.Fields>
<dxpg:PivotGridField Area="DataArea" Caption="Amount" FieldName="amount">
<dxpg:PivotGridField.CellTemplate>
<DataTemplate>
<dxe:TextEdit x:Name="edit" DisplayFormatString="c2" HorizontalContentAlignment="Right"
EditMode="InplaceInactive"
Mask="[0-9]*.[0-9]{0,2}"
MaskType="RegEx"
EditValue="{Binding Value, Mode=OneWay}"
LostFocus="TextEdit_LostFocus"
FocusVisualStyle="{StaticResource TextFocused}">
<dxe:TextEdit.InputBindings>
<MouseBinding MouseAction="LeftClick" Command="{x:Static local:PivotTableView.StartEdit}" CommandParameter="{Binding ElementName=edit}" />
</dxe:TextEdit.InputBindings>
</dxe:TextEdit>
</DataTemplate>
</dxpg:PivotGridField.CellTemplate>
</dxpg:PivotGridField>
<dxpg:PivotGridField Area="RowArea" Caption="Item" FieldName="item" />
<dxpg:PivotGridField Area="ColumnArea" Caption="Name" FieldName="name" />
</dxpg:PivotGridControl.Fields>
</dxpg:PivotGridControl>
這是處理代碼:
void TextEdit_LostFocus(object sender, RoutedEventArgs e)
{
EditValue(sender);
}
static void EditValue(object sender)
{
TextEdit edit = (sender as TextEdit);
if (edit == null || edit.DataContext as CellsAreaItem == null) return;
CellsAreaItem item = edit.DataContext as CellsAreaItem;
decimal newValue;
decimal oldValue;
if (edit.EditValue != null && decimal.TryParse(edit.EditValue.ToString(), out newValue))
{
if (item.Value == null || !decimal.TryParse(item.Value.ToString(), out oldValue))
return;
PivotGridControl pivotGrid = FindParentPivotGrid((DependencyObject)sender);
if (pivotGrid == null)
return;
PivotGridField fieldExtendedPrice = pivotGrid.Fields["amount"];
PivotDrillDownDataSource ds = pivotGrid.CreateDrillDownDataSource(item.ColumnIndex, item.RowIndex);
decimal difference = newValue - oldValue;
decimal factor = (difference == newValue) ? (difference/ds.RowCount) : (difference/oldValue);
for (int i = 0; i < ds.RowCount; i++)
{
decimal value = Convert.ToDecimal(ds[i][fieldExtendedPrice]);
ds[i][fieldExtendedPrice] = (double)((value == 0m) ? factor : value * (1m + factor));//(double)newValue;
}
pivotGrid.RefreshData();
}
}
我使用的版本13.2 。任何想法?提前致謝!!