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

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)