Home Forums WinForms controls Xceed Grid for WinForms SummaryCell or ValueCell – Need text and calc in cell Reply To: SummaryCell or ValueCell – Need text and calc in cell

User (Old forums)
Member
Post count: 23064

Virtualization IS important, because the code I gave you would work fine before we implemented Virtualization in the grid.  The reason it does not work anymore is because the sequence of events has changed, and the painting is not done in all cases, and since the SummaryRow has a different mechanism to update (because it has to know the value of each cell before calculating the StatFunction), it gives inconsistent results.

Investigating this further, we found the reason why it behaves this way, and we found a workaround. I have attached a sample application that works fine (it uses the Northwind DB that is installed by our installer, so it should work as is on Vista, but you may have to update the DB path on XP).  Basically, you have to make sure the Application.Idle event is subscribed to only once.  This means that a private variable (applicationIdlePending) can be use to do this, and it makes the following changes to the code I posted previously :

private Group group;

private bool applicationIdlePending = false;

void Form1_ValueChanged( object sender, EventArgs e )

{

    if( applicationIdlePending )

        return;

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

    DataCell cell = sender as DataCell;

    if( cell != null )

    {

        applicationIdlePending =

true;

        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;

        }

    }

    applicationIdlePending =

false;

}

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