Home Forums WinForms controls Xceed Grid for WinForms How to copy values from SummaryRow to ValueRow for groups in Application.Idle event?

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

    Hi,

    I have a grid with groups. For each group, I have a SummaryRow. I need to make some modifications to the SummaryRow; one thing is that I need to set the title fixed (as in a fixed column), the other thing is that some of the rows should not be included in the summarization, and I therefore want to remove it from the sum. As none of this is possible in the SummaryRow, I create a ValueRow for each SummaryRow in the groups (and I will hide the SummaryRow). I want to copy the title and all values. The title is ok, I copy it when the groups are added. The problem, however, is the sum values, as these are computed as late as possible. I have added an application.idle event on CellValue_Changed, wich loops the groups and tries to copy the values to the ValueRows. The problem is that I end up with the same values in all the groups. How do I distinguish each SummaryRow for the different Group collections?

    Thanks in advance for any help! Any code examples are greatly appreciated.
    Best regards,
    Annette Skår

    Imported from legacy forums. Posted by annetteS (had 590 views)

    User (Old forums)
    Member
    Post count: 23064

    You are probably use a template instead of the actual instance of either the Group, SummaryRow, or ValueRow.  Here is a code snippet demonstrating this, which I optimized a bit, in case you have a large DataSet with many groups.

    private void Form1_Load( object sender, EventArgs e )

    {

        Application.Idle += new EventHandler( First_Application_Idle );

    }

    //This runs only once, after the grid as loaded

    void First_Application_Idle( object sender, EventArgs e )

    {

        Application.Idle -= new EventHandler( First_Application_Idle );

        foreach( Group group in gridControl1.Groups )

        {

            SummaryRow sumRow = group.FooterRows[ 0 ] as SummaryRow;

            ValueRow valueRow = group.FooterRows[ 1 ] as ValueRow;

            if( sumRow != null && valueRow != null )

            {

                valueRow.Cells[

    “SupplierID” ].Value = sumRow.Cells[ “SupplierID” ].Value;

            }

        }

        //Time to subscribe to the ValueChanged event, so we can update the ValueRow accordingly

        dataRowTemplate1.Cells[ “SupplierID” ].ValueChanged += new EventHandler( Form1_ValueChanged );

    }

    private Group group;

    void Form1_ValueChanged( object sender, EventArgs e )

    {

        DataCell cell = sender as DataCell;

        if( cell != null )

        {

            //Get the group of the DataRow that was just updated

            group = cell.ParentRow.ParentGroup as Group;

        }

        Application.Idle += new EventHandler( Application_Idle );

    }

     

    //Do the update to the ValueRow

    void Application_Idle( object sender, EventArgs e )

    {

       

    Application.Idle -= new EventHandler( Application_Idle );

        if( group != null )

        {

            SummaryRow sumRow = group.FooterRows[ 0 ] as SummaryRow;

            ValueRow valueRow = group.FooterRows[ 1 ] as ValueRow;

            if( sumRow != null && valueRow != null )

            {

                valueRow.Cells[

    “SupplierID” ].Value = sumRow.Cells[ “SupplierID” ].Value;

            }

        }

    }

     

    Imported from legacy forums. Posted by André (had 463 views)

    User (Old forums)
    Member
    Post count: 23064

    Hi André,

    Thank you so much for the reply! The code sample you provided made it possible for me to solve my problem (which I have been struggling with for quite some time), so I am very grateful. I was indeed trying to get my groups from my grouptemplates.. which was incorrect..

    Best regards,
    Annette Skår

    Imported from legacy forums. Posted by annetteS (had 926 views)

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