Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
670
Adding new ICustomSummaryCalculator to an ultrawingrid "default" sigma popdown selector. Help please :¬) -Retry 2
posted

I am back for a another go at this and i hope that because i have upgraded to 18.1 i will get a better result

I have a working ICustomSummaryCalculator which adds an "Alway On" summary to my columns

Users would like this ICustomSummaryCalculator  to be added as an option in your summary selector (activated via the sigma button)

Is there any way to do this that does not invole me writing a ton of replacement UI code that basicaly would emulate what you ahve already done

I saw some way to do it with some Web.UI version and some custom summary editor in ASP land so it got my hopes up for c#
www.infragistics.com/.../webdatagrid-adding-custom-summary

If the answer is still NO could you tell me how to hide my ICustomSummaryCalculator  with out removing it
HINT - "SummarySettings.Hidden=false;" does not do anything, it still shows

All appendages crossed here 

Bryan

  • 469350
    Offline posted

    Hi Bryan, 

    This is an interesting puzzle. The dialog itself is not made to be modifiable. There's no list of items you can add to.

    But I don't think it would be too terribly difficult to write code that modifies the dialog and adds an additional Checkbox.

    I took a brief shot at it, and it seems pretty straightforward. Here's the relevant code.

            private void UltraGrid1_BeforeSummaryDialog(object sender, BeforeSummaryDialogEventArgs e)
            {
                // Find the controls we need on the existing dialog. 
                Control summaryControl = e.SummaryDialog.Controls["SummaryControl"];
                Control backgroundPanel = summaryControl.Controls["ultraBackgroundPanel"];
                Control cancelUltraButton = backgroundPanel.Controls["cancelUltraButton"];
                Control okUltraButton = backgroundPanel.Controls["okUltraButton"];
                Control panelCheckboxes = backgroundPanel.Controls["panelCheckboxes"];
                Control sumCheckBox = panelCheckboxes.Controls["sumCheckBox"];
    
                // I am assuming that the application allows multiple summaries, so 
                // the dialog is using CheckBoxes. For a single summary, it would use radio buttons
                // and you would need to use these two controls and change the code below to add
                // a RadioButton insetad of a CheckBox. 
                //
                //Control panelRadios = backgroundPanel.Controls["panelRadios"];
                //Control sumRadio = panelRadios.Controls["sumRadio"];
                            
                this.myCheckBox = new CheckBox();
                this.myCheckBox.Name = "myCheckBox";
                this.myCheckBox.Text = "My custom summary type";
                this.myCheckBox.SetBounds(
                    sumCheckBox.Left,
                    sumCheckBox.Bottom + 4,
                    sumCheckBox.Width,
                    sumCheckBox.Height
                    );
    
                if (DoesCustomSummaryAlreadyExist(e.Column))
                    this.myCheckBox.Checked = true;
    
                // You will proabably want to add an image to the CheckBox here so it will look 
                // consistent with the other checkboxes. 
                //this.myCheckBox.Image = myImage;
    
    
                // The dialog and the controls need to be shifted and resized to accomodate
                // the new control. 
                int heightAdjustment = this.myCheckBox.Height + 4;
                panelCheckboxes.Height += heightAdjustment;
                e.SummaryDialog.Height += heightAdjustment;
                okUltraButton.Top += heightAdjustment;
                cancelUltraButton.Top += heightAdjustment;
    
                panelCheckboxes.Controls.Add(myCheckBox);
            }
    
            private void UltraGrid1_AfterSummaryDialog(object sender, AfterSummaryDialogEventArgs e)
            { 
                if (null != this.myCheckBox)
                {
                    string myCustomSummaryKey = GetMyCustomSummaryKey(e.Column);
                    bool customSummaryAlreadyExists = DoesCustomSummaryAlreadyExist(e.Column);
                    if (this.myCheckBox.Checked && !customSummaryAlreadyExists)
                    {
                        // I used a Formula summary here as a placeholder so I didn't have to 
                        // create an ICustomSummaryCalculator. But you would use SummaryType.Custom
                        // and use an overload of Summaries.Add that takes an ICustomSummaryCalculator.
                        e.Column.Band.Summaries.Add(myCustomSummaryKey, SummaryType.Formula, e.Column);
                    }
                    else if (!this.myCheckBox.Checked && customSummaryAlreadyExists)
                    {
                        var ss = e.Column.Band.Summaries[myCustomSummaryKey];
                        e.Column.Band.Summaries.Remove(ss);
                    }
    
                    this.myCheckBox.Dispose();
                    this.myCheckBox = null;
                }
            }
    
            private bool DoesCustomSummaryAlreadyExist(UltraGridColumn column)
            {
                string myCustomSummaryKey = GetMyCustomSummaryKey(column);
                return column.Band.Summaries.Exists(myCustomSummaryKey);
            }
    
            private string GetMyCustomSummaryKey(UltraGridColumn column)
            {
                return string.Format("MyCustomSummaryColumn - {0}", column.Key);
            }

    And I also attached a working sample.WinGrid - Custom Item on Summaryt Dialog.zip