Home Forums WPF controls Xceed DataGrid for WPF How to Implement Statistics in Code ( StatFunctions , StatRow ,StatCell ,Footer )

Viewing 12 posts - 1 through 12 (of 12 total)
  • Author
    Posts
  • User (Old forums)
    Member
    Post count: 23064
    #26898 |

    Hi !

    Can you please guide me in  Implementing  Statistics in Code  like defining  StatFunctions  , StatRow and  StatCell and assign this StatRow to Footer .

     

    Thank you !

    Rachana

    Imported from legacy forums. Posted by Rachana (had 4782 views)

    User (Old forums)
    Member
    Post count: 23064

    Here i”m placing the code

     

    public const string ENTITY_GRID_COLUMN_EID = “Id”;

    public const string ENTITY_GRID_COLUMN_ENAME = “Name”;

    public const string ENTITY_GRID_COLUMN_CITY = “City”;

    public const string ENTITY_GRID_COLUMN_STATE = “State”;

    public const string ENTITY_GRID_COLUMN_STATUS = “Status”;

    public const string ENTITY_GRID_COLUMN_CLASS = “Class”;

    public const string ENTITY_GRID_COLUMN_TYPE = “Type”;

    public const string ENTITY_GRID_COLUMN_NO_OF_BUILDINGS = “# Buildings”;

    public const string ENTITY_GRID_COLUMN_NO_OF_UNITS = “# Units”;

    public const string ENTITY_GRID_COLUMN_MEMO = “Memo”;

    public const string ENTITY_GRID_COLUMN_SQUARE_FOOTAGE = “Square Footage”;

    public const string ENTITY_GRID_COLUMN_ENTITY_DATE = “Entity Date”;

    public const string ENTITY_GRID_COLUMN_HIGHLIGHT = “Highlight”;

    #endregion

    #region

    Constructor

    public MainWindow()

    {

    InitializeComponent();

    this.chkHeaderRow.IsChecked = true;

    this.rbtnDefault.IsChecked = true;

    PopulateGrid();

    }

    #endregion

    #region

    Private Methods

    private void PopulateGrid()

    {

    DataTable dt = new DataTable();

    dt.Columns.Add(

    new DataColumn(ENTITY_GRID_COLUMN_EID, typeof(int)));

    dt.Columns.Add(

    new DataColumn(ENTITY_GRID_COLUMN_ENAME, typeof(string)));

    dt.Columns.Add(

    new DataColumn(ENTITY_GRID_COLUMN_CITY, typeof(string)));

    dt.Columns.Add(

    new DataColumn(ENTITY_GRID_COLUMN_STATE, typeof(string)));

    dt.Columns.Add(

    new DataColumn(ENTITY_GRID_COLUMN_STATUS, typeof(string)));

    dt.Columns.Add(

    new DataColumn(ENTITY_GRID_COLUMN_CLASS, typeof(string)));

    dt.Columns.Add(

    new DataColumn(ENTITY_GRID_COLUMN_TYPE, typeof(string)));

    dt.Columns.Add(

    new DataColumn(ENTITY_GRID_COLUMN_NO_OF_BUILDINGS, typeof(int)));

    dt.Columns.Add(

    new DataColumn(ENTITY_GRID_COLUMN_NO_OF_UNITS, typeof(int)));

    dt.Columns.Add(

    new DataColumn(ENTITY_GRID_COLUMN_MEMO, typeof(string)));

    dt.Columns.Add(

    new DataColumn(ENTITY_GRID_COLUMN_SQUARE_FOOTAGE, typeof(string)));

    dt.Columns.Add(

    new DataColumn(ENTITY_GRID_COLUMN_ENTITY_DATE, typeof(DateTime)));

    dt.Columns.Add(

    new DataColumn(ENTITY_GRID_COLUMN_HIGHLIGHT, typeof(string)));

    EntityUI entityUI = new EntityUI();

    EntityDTO[] entities = entityUI.Lookup(new EntityDTO());

    System.Data.

    DataRow dr = null;

    if (entities != null && entities.Length > 0)

    {

    foreach (EntityDTO entity in entities)

    {

    dr = dt.NewRow();

    dr[ENTITY_GRID_COLUMN_EID] = entity.entityId;

    dr[ENTITY_GRID_COLUMN_ENAME] = entity.entityName;

    dr[ENTITY_GRID_COLUMN_CITY] = entity.city;

    dr[ENTITY_GRID_COLUMN_STATE] = entity.state;

    dr[ENTITY_GRID_COLUMN_STATUS] = entity.status.statusName;

    dr[ENTITY_GRID_COLUMN_CLASS] = entity.keyFacts.classObj.className;

    dr[ENTITY_GRID_COLUMN_TYPE] = entity.keyFacts.type.typeName;

    dr[ENTITY_GRID_COLUMN_NO_OF_BUILDINGS] = entity.keyFacts.numberOfBuildings;

    dr[ENTITY_GRID_COLUMN_NO_OF_UNITS] = entity.keyFacts.numberOfUnits;

    dr[ENTITY_GRID_COLUMN_MEMO] = entity.keyFacts.memo;

    dr[ENTITY_GRID_COLUMN_SQUARE_FOOTAGE] = entity.keyFacts.squareFootage;

    dr[ENTITY_GRID_COLUMN_ENTITY_DATE] = entity.entGenInfo.entityDate;

    dr[ENTITY_GRID_COLUMN_HIGHLIGHT] =

    “N”;

    dt.Rows.Add(dr);

    }

    }

    DataView dv = new DataView(dt);

    Binding binding = new Binding();

    binding.Source = dv;

    DataGridCollectionView dataGridCollectionView = new DataGridCollectionView((IEnumerable)dv);

    dataGridCollectionView.AutoFilterMode =

    AutoFilterMode.And;

    dataGridCollectionView.DistinctValuesConstraint =

    DistinctValuesConstraint.Filtered;

     

     

     

    SumFunction sf = new SumFunction();

    sf.SourcePropertyName = ENTITY_GRID_COLUMN_EID;

    sf.ResultPropertyName =

    “sumEID”;

    dataGridCollectionView.StatFunctions.Add(sf);

     

    /* <xceed:DataGridControl.DefaultGroupConfiguration>

    <xceed:GroupConfiguration>

    <xceed:GroupConfiguration.Footers>

    <DataTemplate>

    <xceed:StatRow Background=”AliceBlue”>

     

    <xceed:StatCell FieldName=”Id” ResultPropertyName=”MinOfReorderLevel”/>

    <xceed:StatCell FieldName=”Name” ResultPropertyName=”SumBuildings”/>

    <xceed:StatCell FieldName=”Type” ResultPropertyName=”MaxOfReorderLevel”/>

     

    </xceed:StatRow>

    </DataTemplate>

    </xceed:GroupConfiguration.Footers>

    </xceed:GroupConfiguration>

    </xceed:DataGridControl.DefaultGroupConfiguration> */

     

    StatRow sr = new StatRow();

    sr.Name =

    “sr”;

    GroupConfiguration gc = new GroupConfiguration();

    DataTemplate dtemp = new DataTemplate();

    FrameworkElementFactory control = new FrameworkElementFactory(typeof(StatRow), sr.Name);

    StatCell sc = new StatCell();

    sc.FieldName = ENTITY_GRID_COLUMN_EID;

    sc.ResultPropertyName =

    “sumEID”;

    sr.Cells.Add(sc);

    control.SetBinding( items

    dtemp.VisualTree = control;

    gc.Footers.Add(dtemp);

     

    dataGrid.DefaultGroupConfiguration = gc;

     

     

    // dataGridView.FixedFooters.Add(dtemp);;

    //sr.Resources.Add(

    //dataGridCollectionView.StatFunctions.Add(Xceed.wpd

    dataGrid.ItemsSource = dataGridCollectionView;

     

     Please tell me hoe to add  StatRow to Datatemplete

     

     

    Imported from legacy forums. Posted by Rachana (had 1582 views)

    Xceed Support
    Member
    Post count: 5658

    Hi Rachana,

       You simply reached the limit of what can be done when trying to build templates through code…

       Here is an excerpt of the MSDN documentation regarding the creation of templates through code:

       Remarks regarding FrameworkElementFactory:
        
    This class is a deprecated way to programmatically create templates, which
    are subclasses of FrameworkTemplate such as ControlTemplate or DataTemplate; not all of the
    template functionality is available when you create a template using this class.
    The recommended way to programmatically create a template is to load XAML from a
    string or a memory stream using the Load method of the XamlReader class.

     

    Imported from legacy forums. Posted by Marcus [Xceed] (had 1473 views)

    User (Old forums)
    Member
    Post count: 23064

    Same thing here.

    I have a DataTable whereby the columns are not know till run time (as the user can select various criteria that we end up pulling into the datatabe), some of these columns need StatFunctions.I know what columns need functions for at run time, I just need to know the correct way to access the information to create the DataTemplate for the StatFunctions.
     
    If xmal is the preferred way is it possible to make a custom datatemplate in xmal that somehow bound to an object that contains the information about the columns, for example a ReportDefinition object.

    Any ideas?

    Imported from legacy forums. Posted by Keith (had 997 views)

    User (Old forums)
    Member
    Post count: 23064

    Hello,

     

    Did you find a way to do this?  I am having the same issue.

     

    Basically I want my Grid to look like the StatFunction example (with group totals and the overall totals).  But I don’t know what table and what columns (and what columns will be totaled) will be used until runtime…. 

     

    On a side note..err question….if you do have group totals and a grand total….can that be printed?  Exported to .xps?

     

     

    Imported from legacy forums. Posted by Dave (had 1782 views)

    User (Old forums)
    Member
    Post count: 23064

    If anyone cares I have managed to get this to work….[:P]

     

    I thought I would share the code…if there is a better way I would love to hear about it…pleases remember this is just a rough draft and I plan to tweak this alot but it should help others get started if they want to do this.

     

    // report1.Total_sum and report1.Group_Sum are String Lists that have the exact field names from the database that I want to make group sums and

    // total sum for  (I copied alot of the xaml code from the StatFunction demo that Xceed provides)

     
                int i1=0;
                foreach (String s11 in report1.Total_Sum)
                {
                    Xceed.Wpf.DataGrid.Stats.SumFunction sumfunc1 = new Xceed.Wpf.DataGrid.Stats.SumFunction();
                    //sumfunc1.SourcePropertyName = “Total_Sum_Source_” + s11 + i1.ToString();
                    sumfunc1.SourcePropertyName = s11;
                    sumfunc1.ResultPropertyName = “Total_Sum_Result_” + s11 + “__” + i1.ToString();
                    ((Xceed.Wpf.DataGrid.DataGridCollectionView)dataGridControl1.ItemsSource).StatFunctions.Add(sumfunc1);
                    i1++;
                }

     

                i1 = 0;
                foreach (String s11 in report1.Group_Sum)
                {
                    Xceed.Wpf.DataGrid.Stats.SumFunction sumfunc1 = new Xceed.Wpf.DataGrid.Stats.SumFunction();
                    //sumfunc1.SourcePropertyName = “Group_Sum_Source_” + s11 + i1.ToString();
                    sumfunc1.SourcePropertyName = s11;
                    sumfunc1.ResultPropertyName = “Group_Sum_Result_” + s11 + “__” + i1.ToString();
                    ((Xceed.Wpf.DataGrid.DataGridCollectionView)dataGridControl1.ItemsSource).StatFunctions.Add(sumfunc1);
                    i1++;
                }

     

     

    // I then need to make a ResourceDictionary in code as a string

     

            private void Create_ResourceDictionary_For_Stat_Functions_TableView()
            {

                if ((report1.Total_Sum.Count < 1) && (report1.Group_Sum.Count < 1))
                    return;

                String s1;
                
                s1 = “<ResourceDictionary xmlns=\”http://schemas.microsoft.com/winfx/2006/xaml/presentation\” xmlns:x=\”http://schemas.microsoft.com/winfx/2006/xaml\” xmlns:xcdg=\”http://schemas.xceed.com/wpf/xaml/datagrid\”>”;
                //This StatCell Style will display, above the result, a line or a double line depending on whether the StatCell is in a group or not. –>
                s1 += “<Style x:Key=\”tableViewTotalStatCellStyle\” TargetType=\”xcdg:StatCell\”>”;
                //The line(s) will be of the same color as the HorizontalGridLine. –>
                s1 += “<Setter Property=\”BorderBrush\” Value=\”{Binding RelativeSource={RelativeSource Self}, Path=(xcdg:DataGridControl.DataGridContext).HorizontalGridLineBrush}\”/>”;
                s1 += “<Setter Property=\”Template\”>”;
                s1 += “<Setter.Value>”;
                s1 += “<ControlTemplate TargetType=\”xcdg:StatCell\”>”;
                s1 += “<Border Background=\”{TemplateBinding Background}\” BorderBrush=\”{TemplateBinding BorderBrush}\” BorderThickness=\”{TemplateBinding BorderThickness}\” Padding=\”{TemplateBinding Padding}\”>”;
                s1 += “<StackPanel>”;
                s1 += “<Border x:Name=\”totalBorder\” BorderBrush=\”{TemplateBinding BorderBrush}\” BorderThickness=\”0,1,0,0\”/>”;
                s1 += “<ContentPresenter Content=\”{xcdg:CellContentBinding}\” ContentTemplate=\”{TemplateBinding ContentTemplate}\” ContentTemplateSelector=\”{TemplateBinding ContentTemplateSelector}\” HorizontalAlignment=\”{TemplateBinding HorizontalContentAlignment}\” VerticalAlignment=\”{TemplateBinding VerticalContentAlignment}\” />”;
                s1 += “</StackPanel>”;
                s1 += “</Border>”;
                s1 += “<ControlTemplate.Triggers>”;
                s1 += “<DataTrigger Binding=\”{Binding RelativeSource={RelativeSource Self}, Path=ParentColumn.Visible}\” Value=\”False\”>”;
                s1 += “<Setter Property=\”Visibility\” Value=\”Collapsed\”/>”;
                s1 += “</DataTrigger>”;
                
                //      <!– When the StatCell is not inside a Group, display a double line. –>
                s1 += “<Trigger Property=\”xcdg:GroupLevelIndicatorPane.GroupLevel\” Value=\”-1\”>”;
                s1 += “<Setter TargetName=\”totalBorder\” Property=\”BorderThickness\” Value=\”0,1,0,1\”/>”;
                s1 += “<Setter TargetName=\”totalBorder\” Property=\”Padding\” Value=\”0,2,0,0\”/>”;
                s1 += “</Trigger>”;
                //     <!– When the StatCell has no content, don’t display any line above. –>
                s1 += “<Trigger Property=\”HasContent\” Value=\”False\”>”;
                s1 += “<Setter TargetName=\”totalBorder\” Property=\”BorderThickness\” Value=\”0\”/>”;
                s1 += “</Trigger>”;
                s1 += “</ControlTemplate.Triggers>”;
                s1 += “</ControlTemplate>”;
                s1 += “</Setter.Value>”;
                s1 += “</Setter>”;
                s1 += “</Style>”;
                // StatFunction results can be “fetched” in any content control by using a
                // binding on the StatContext property. This StatContext exposes, as properties,
                // all the StatFunctions declared in the DataGridCollectionViewSource.
                // This template will be added to the TableView in code. –>
                /*
                s1 += “<DataTemplate x:Key=\”tableViewHeader1\”>”;
                s1 += “<Border Margin=\”4\””;
                s1 += “TextElement.FontSize=\”14\””;
                s1 += “TextElement.FontWeight=\”Bold\”>”;
                s1 += “<StackPanel Orientation=\”Horizontal\” ToolTip=\”Only products that have a reorder level of 5, 10, 15, or 20, and units on order of 0 will be counted.”>
                <TextBlock TextWrapping=”Wrap”
                           Text=”Number of products to reorder : “/>
                <TextBlock Text=”{Binding RelativeSource={RelativeSource Self},Path=(xcdg:DataGridControl.StatContext).CountProductsToOrder}”/>
             </StackPanel>
          </Border>
       </DataTemplate>*/

                // <!– A GroupConfiguration allows you to control the content (headers/footers)
                //      and behavior of same-level groups.
                //      This GroupConfiguration will be added to the TableView in code and will
                //      dictate the behavior and content of the groups. –>
                
                int i1 = 0;
                if(report1.Group_Sum.Count >0)
                {
                    s1 += “<xcdg:GroupConfiguration x:Key=\”tableViewGroupConfiguration1\”>”;
                    s1 += “<xcdg:GroupConfiguration.Footers>”;
                    //<!– The groups will contain a StatRow visible even when the group is collapsed. –>
                    s1 += “<xcdg:GroupHeaderFooterItemTemplate VisibleWhenCollapsed=\”True\”>”;
                    s1 += “<DataTemplate>”;
                    s1 += “<xcdg:StatRow>”;
                    
                    foreach(String s111 in report1.Group_Sum)
                    {
                        //<!– The following three cells simply refer to the previously declared StatFunctions using the ResultPropertyName property. –>
                        // sumfunc1.SourcePropertyName = “Group_Sum_Source_” + report1.Group_Sum[i1] + i1.ToString();
                        // sumfunc1.ResultPropertyName = “Group_Sum_Result_” + report1.Group_Sum[i1] + i1.ToString();
                        
                        s1 += “<xcdg:StatCell FieldName=\”” + s111 + “\” ResultPropertyName=\”” +”Group_Sum_Result_” + report1.Group_Sum[i1] + “__” + i1.ToString() + “\” Style=\”{StaticResource tableViewTotalStatCellStyle}\”/>”;
                        i1++;
                    }  
                    s1 += “</xcdg:StatRow>”;
                    s1 += “</DataTemplate>”;
                    s1 += “</xcdg:GroupHeaderFooterItemTemplate>”;
                    s1 += “</xcdg:GroupConfiguration.Footers>”;
                    s1 += “</xcdg:GroupConfiguration>”;
                    
                }
                    
            
                    
                i1 = 0;
                if(report1.Total_Sum.Count >0)
                {
                    // <!– This template will be added to the TableView in code. –>
                    s1 += “<DataTemplate x:Key=\”tableViewFixedFooter1\”>”;
                    s1 += “<xcdg:StatRow>”;
                    s1 += “<xcdg:StatRow.Resources>”;
                    s1 += “<Style TargetType=\”xcdg:StatCell\” BasedOn=\”{StaticResource tableViewTotalStatCellStyle}\”/>”;
                    s1 += “</xcdg:StatRow.Resources>”;
                    //  <!– Each StatCell has a default StatResultConverter assigned to it,
                    //       allowing only a ConverterParameter that will format
                    //       the result to be specified. To improve its usage in XAML, the StatResultConverter’s
                    //       parameter supports a simplified syntax of composite formatting.
                    //       Refer to the documentation for more informations. –>

                    foreach(String s111 in report1.Total_Sum)
                    {
                        s1 += “<xcdg:StatCell FieldName=\”” + s111 + “\” ResultPropertyName=\”” +”Total_Sum_Result_” + report1.Total_Sum[i1] + “__” + i1.ToString() + “\” Style=\”{StaticResource tableViewTotalStatCellStyle}\”/>”;
                        //s1 += “<xcdg:StatCell FieldName=\”UnitsInStock\” ResultPropertyName=\”SumOfUnitsInStock\”/>”;
                        i1++;
                    }
                    s1 += “</xcdg:StatRow>”;
                    s1 += “</DataTemplate>”;
                    s1 += “</ResourceDictionary>”;
                }
                

     

    // This is how I load the new resource dictionary I just made

                MemoryStream stream = new MemoryStream(Encoding.UTF8.GetBytes(s1));
                ResourceDictionary rd = null;
                rd = (ResourceDictionary)XamlReader.Load(stream);
                Application.Current.Resources = rd;
                //Application.Current.Resources.Clear();

                
            }

     

     

     

    //  And now use this new resource dictionary…..you need to add it like this…

     

                if(report1.Total_Sum.Count > 0)
                    dataGridControl1.View.FixedFooters.Add( ( DataTemplate )this.FindResource( “tableViewFixedFooter1” ) );
                if(report1.Group_Sum.Count > 0)
                    dataGridControl1.DefaultGroupConfiguration = ( GroupConfiguration )this.FindResource( “tableViewGroupConfiguration1” );
     

     

     

    Imported from legacy forums. Posted by David (had 1247 views)

    User (Old forums)
    Member
    Post count: 23064

    [quote user=”Marcus”]

    Hi Rachana,

       You simply reached the limit of what can be done when trying to build templates through code…

       Here is an excerpt of the MSDN documentation regarding the creation of templates through code:

       Remarks regarding FrameworkElementFactory:
        
    This class is a deprecated way to programmatically create templates, which
    are subclasses of FrameworkTemplate such as ControlTemplate or DataTemplate; not all of the
    template functionality is available when you create a template using this class.
    The recommended way to programmatically create a template is to load XAML from a
    string or a memory stream using the Load method of the XamlReader class.

     

    [/quote]

    Are you kidding? Just because you cannot use the FrameworkElementFactory that is it? Though luck? Don’t use our product because we could not be bothered to give you guys a way to do it???

    We generate a grid based on the structure of a data table. We do not know beforehand how many columns there will be but we do have configuration information for each grid column. Part of this configuration information is if the column should have a sum or average or so on.

    Is there any way to show statistics for a column other than creating a data template in an in-memory string?

    Imported from legacy forums. Posted by Du Toit (had 1023 views)

    Xceed Support
    Member
    Post count: 5658

    <quote>
    Are you kidding? Just because you cannot use the
    FrameworkElementFactory that is it? Though luck? Don’t use our product
    because we could not be bothered to give you guys a way to do it???
    </quote>

    Well, it was more intended to be interpreted this way: There is a limitation both in the API and in the Framework that prevents you from creating a StatRow DataTemplate through code using a FrameworkElementFactory, the recommended way to programmatically create such a template is to load XAML from a
    string or a memory stream using the Load method of the XamlReader class.  [:P]

    <quote>
    Is there any way to show statistics for a column other than creating a data template in an in-memory string?
    </quote>

    Unfortunately, based on your need to for dynamism, I do not see a solution other than to create the DataTemplate for the StatRow as a dynamically built XAML string, parsed into a DataTemplate.

    Imported from legacy forums. Posted by Marcus [Xceed] (had 710 views)

    User (Old forums)
    Member
    Post count: 23064

    Woot, I actually found something that works!

    [Quote]’This sub creates the Xceed columns based on our own setting in _OrderedColumns
    Private Sub SetupGridColumns
      Me.MainGrid.Columns.Clear()
      Me.MainGrid.UpdateSourceTrigger = DataGridUpdateSourceTrigger.CellContentChanged

      Dim xc As Xceed.Wpf.DataGrid.Column
      For Each c As GridColumnSettings In _OrderedColumns
        Dim columnKey As String = c.ColumnName
        xc = MainGrid.Columns(columnKey)
        If xc Is Nothing Then
            xc = New Xceed.Wpf.DataGrid.Column
            xc.FieldName = columnKey
            Me.MainGrid.Columns.Add(xc)
        End If
        xc.Title = c.DisplayName
        If c.ShowSum = True Then
          Dim xcView As Xceed.Wpf.DataGrid.DataGridCollectionView
          xcView = MainGrid.ItemsSource
          xcView.StatFunctions.Add(New Stats.SumFunction(c.ColumnName & “_XC_STATS”, c.ColumnName))
        End If
      Next
      Me.MainGrid.View.FixedFooters.Add(CType(Me.FindResource(“tableViewFixedFooter1”), DataTemplate))
    End Sub

    ‘This works. No idea why, but it does
    Private _statRow As StatRow = Nothing
    Private Sub StatRow_Loaded(ByVal sender As System.Object, ByVal e As System.Windows.RoutedEventArgs)
      _statRow = sender
      For Each sCell As StatCell In _statRow.Cells
        If _OrderedColumns.ContainsKey(sCell.FieldName) Then

          Dim col As GridColumnSettings = _OrderedColumns(sCell.FieldName)
          sCell.ResultPropertyName = sCell.FieldName & “_XC_STATS”
          If col.OutputFormat <> “” Then
            sCell.ResultConverterParameter = col.OutputFormat
          End If
        End If
      Next
    End Sub

    <!– I got this template from the Statistics Demo and removed all the StatCell entries from it
         and added the Loaded=”StatRow_Loaded” handler. –>
    <DataTemplate x:Key=”tableViewFixedFooter1″>
      <xcdg:StatRow Loaded=”StatRow_Loaded”>
        <xcdg:StatRow.Resources>

          <Style TargetType=”xcdg:StatCell” BasedOn=”{StaticResource tableViewTotalStatCellStyle}”/>
        </xcdg:StatRow.Resources>
      </xcdg:StatRow>
    </DataTemplate>[/Quote]

    Imported from legacy forums. Posted by Du Toit (had 1177 views)

    User (Old forums)
    Member
    Post count: 23064

    I am having a small problem with allowing the user to switch to using different calculations in the Group Calculations.

    For instance lets say I have column A1 and that is initially set for the Group Sum calculation.  Initially it works great.  Now when the user selects a new way they would like to calculate column A1  (lets say they select to use the Count calc) it doesn’t Count.  (There are no calculations done at all in that group in column A1.)  But if the user goes back to Sum it works again. It does the Sum calculation as expected.

     

    I use this line of code to remove the current calculations in memory.

    ((Xceed.Wpf.DataGrid.DataGridCollectionView)dataGridControl1.ItemsSource).StatFunctions.Clear();

    I then redo all the calculations after the line above like:

                        if (f11.Total_Calculation_Type == Calculation_Type.COUNT)
                        {
                            Xceed.Wpf.DataGrid.Stats.SumFunction sumfunc1 = new Xceed.Wpf.DataGrid.Stats.SumFunction();
                            sumfunc1.SourcePropertyName = f11.Field_Name;
                            sumfunc1.ResultPropertyName = “Total_Count_Result_” + f11.Field_Name + “__” + i1.ToString();
                            ((Xceed.Wpf.DataGrid.DataGridCollectionView)dataGridControl1.ItemsSource).StatFunctions.Add(sumfunc1);
                        }

     

    My suspicions are that after this line:

    ((Xceed.Wpf.DataGrid.DataGridCollectionView)dataGridControl1.ItemsSource).StatFunctions.Clear();

    The calculations are somewhere still stuck in memory perhaps?

     

    Imported from legacy forums. Posted by David (had 830 views)

    User (Old forums)
    Member
    Post count: 23064

    Well if anyone cares….I do have a solution to the above message.  It might not be the most ideal solution but it works.

    Bascially for each column I initially load into memory the SumFunction, and the CountFunction and the AverageFunction and I don’t even bother to try to use:

    ((Xceed.Wpf.DataGrid.DataGridCollectionView)dataGridControl1.ItemsSource).StatFunctions.Clear();

    This way I can switch group stat functions on the fly…from lets say a CountFunction to the SumFunction on the same column.

    Imported from legacy forums. Posted by David (had 1632 views)

    User (Old forums)
    Member
    Post count: 23064

    I think people failed to realize that DataTemplates can be Statically made in XAML and Dynamically assigned in C#

    Just my two cents (on an old post too, I must be bored)

    Imported from legacy forums. Posted by MiddleTommy (had 4376 views)

Viewing 12 posts - 1 through 12 (of 12 total)
  • You must be logged in to reply to this topic.