Hello!
I have a measure of my custom type "SplitValue", so my data is split in two parts and in PivotGrid the sum of two parts is shown. I've already managed to show these values in PivotGrid by writing custom aggregator, but I need to edit both of underlying values. I want to create a edit template with two textboxes instead of one, but I can't find a way to do this.
How can I do this?
Hello and thank you for posting!
I have been looking into your scenario and a possible solution here would be create the cell template like it is described in the following documentation page http://help.infragistics.com/Help/Doc/WPF/2014.1/CLR4.0/html/xamPivotGrid_Customizing_Cells_with_Templates_Procedure_and_Code_Example.html and apply it when the CellEnterEdit event is fired.Please feel free to let me know if you have any questions or concerns.
But how do I remove that template when editing has finished? OnCellEdited event only fires when editing is approved, but how to revert the template when edit is canceled (Esc is pressed)?
Hi,
The CellEdited event is fired after the cell exit edit mode and could be used to change the template to the default one that could be found under the Infragistics folder on your machine (C:\Program Files (x86)\Infragistics\2014.1\WPF\DefaultStyles\XamPivotGrid) or with other template.
And additional problem here: if I'll change the template to the default one as you suggested, I'll lose all templates defined in XamPivotGrid.DataCellTemplates. So, default template isn't suitable here: I need to revert to the previous template, not he default one.
Hello,
Another approach that could be used here is changing EditorStyle and modifying the default template of the TextBox control. Here is a code snippet for the same:<Style x:Key="EditorStyle" TargetType="TextBox"> <Setter Property="BorderThickness" Value="1"/> <Setter Property="Padding" Value="2"/> <Setter Property="Margin" Value="0"/> <Setter Property="Foreground" Value="#FF333333"/> <Setter Property="BorderBrush" Value="Blue"/> <Setter Property="Background" Value="Red"/> <Setter Property="Template"> <Setter.Value> <ControlTemplate> <StackPanel Orientation="Horizontal"> <TextBox Text="{Binding RelativeSource={RelativeSource AncestorType={x:Type TextBox}},Path=Text}" Background="Yellow"/> <TextBox Text="mhgfkjg" Background="Green"/> </StackPanel> </ControlTemplate> </Setter.Value> </Setter> </Style>I am also attaching the sample project I have used to test the same. Please feel free to let me know whether this helps.
Thank you for your feedback and for using Infragistics components. I am glad the issue is resolved.
Thank you Maria, yes, your answer pointed me in the right direction.
I am just checking if you have any other questions on getting the underlying data of a cell.
I am glad that the suggested approach helps you get closer to the functionality you need. The approach that is suggested by Plamen in the following forum thread is regarding the access to the underlying data: http://ko.infragistics.com/community/forums/t/56647.aspx Here is how I have modified the approach so that it suits to the project I have previously attached:private void pivotGrid_CellEditing(object sender, Infragistics.Controls.Grids.PivotCellEditingEventArgs e) { int units = 0; StackPanel panel = Infragistics.Windows.Utilities.GetDescendantFromType(e.Editor, typeof(StackPanel), false) as StackPanel; int columnIndex = pivotGrid.DataColumns.IndexOf(e.Cell.DataColumn); int rowIndex = pivotGrid.DataRows.IndexOf(e.Cell.DataRow); FlatDataSource flatDataSource = (FlatDataSource)this.pivotGrid.DataSource; List<int> itemsIndexes = flatDataSource.GetCellItemsIndexes(pivotGrid.DataSource.Result.Cells[rowIndex, columnIndex]); foreach (int itemIndex in itemsIndexes) {
object dataItem = flatDataSource.GetRecord(itemIndex); units += ((Sale)dataItem).NumberOfUnits; } (panel.Children[1] as TextBox).Text = units.ToString();}I hope it will be useful.
Thank you Maria! That's what I want.
The only issue that I have left now is: how to bind to underlying value of the cell? All I can do yet is to bind to the string representation of this object. I wrote a custom aggregator, so now I have correct objects, but can't bind to them.