Xceed Grid for WinForms v4.3 Documentation
Using the DataRowsChanged event

Welcome to Xceed Grid for WinForms v4.3 > Basic Concepts > Events > Using the DataRowsChanged event

The DataRowsChanged and SiblingDataRowsChanged events are raised when a data row or a sibling data row has been modified, added or deleted from the grid. They are also raised when the value of a cell in a data row changes, as well as when a row leaves edit mode.

The events will be raised in the following order:

  1. The DataRowsChanged event will be raised for the Group that has the lowest level. (gridControl.Groups.Count - 1) 

  2. The SiblingDataRowsChanged event will be raised once for each row found in the group's HeaderRows section. 

  3. The SiblingDataRowsChanged event will be raised once for each row found in the group's FooterRows section. 

  4. The DataRowsChanged event will be raised for each other of the row's parent groups, continuing with the one that has the second lowest level, (gridControl.Groups.Count - 2), until there are no more groups. 

  5. The SiblingDataRowsChanged event will be raised for each row in each group's HeaderRows section. This is done after each parent group's DataRowsChanged event. 

  6. The SiblingDataRowsChanged event will be raised for each row in each group's FooterRows section. This is done after the SiblingDataRowsChanged event has been raised for each row in the same group's HeaderRows section. 

  7. The DataRowsChanged event will be raised for the grid. 

  8. The SiblingDataRowsChanged event will be raised for each row in the grid's FixedHeaderRows section. 

  9. The SiblingDataRowsChanged event will be raised for each row in the grid's HeaderRows section. 

  10. The SiblingDataRowsChanged event will be raised for each row in the grid's FooterRows section. 

  11. The SiblingDataRowsChanged event will be raised for each row in the grid's FixedFooterRows section.

The following image represents the order in which the DataRowsChanged and SiblingDataRowsChanged events will be raised. The numbers represent the steps described above:

 

Purpose

The purpose of the DataRowsChanged and SiblingDataRowsChanged event is to provide notification to other grid element's that the content of the grid has been modified. This can be useful in cases where you need to update information that is displayed in rows such as the GroupManagerRow or SummaryRow.

Basic steps - C#

To subscribe to the DataRowsChanged and/or SiblingDataRowsChanged events, the following steps must be performed:

Basic steps - VB.NET

To subscribe to the DataRowsChanged and/or SiblingDataRowsChanged events, the following steps must be performed:

Demonstration

This example assumes that you are in a Windows application.

VB.NET
Copy Code
AddHandler textRow1.SiblingDataRowsChanged, AddressOf Me.textRow1_SiblingDataRowsChanged

Private Sub textRow1_SiblingDataRowsChanged(ByVal sender As Object, ByVal e As EventArgs)

Dim averageRow As TextRow = sender

Dim total As Decimal = 0

Dim row As Xceed.Grid.DataRow

Try

  For Each row In averageRow.ParentGroup.GetSortedDataRows( false )

    total += row.Cells( "Freight" ).Value

  Next row

  total = total / averageRow.ParentGroup.GetSortedDataRowCount( false )

  total = Math.Round( total, 3 )

  averageRow.Text = "The average freight for this group is " + total.ToString()

Catch exception As Exception

  MessageBox.Show( exception.ToString() )

End Try

End Sub



' If you no longer wish to handle the SiblingDataRowsChangedevents that are raised,

' you can unsubscribe from the event notification by doing the following:

RemoveHandler textRow1.SiblingDataRowsChanged, AddressOf Me.textRow1_SiblingDataRowsChanged
C#
Copy Code
textRow1.SiblingDataRowsChanged += new EventHandler( this.textRow1_SiblingDataRowsChanged );

private void textRow1_SiblingDataRowsChanged(object sender, System.EventArgs e)

{

  TextRow averageRow = ( TextRow )sender;

  decimal total = 0; 

 

  try

  {

    foreach( Xceed.Grid.DataRow row in averageRow.ParentGroup.GetSortedDataRows( false ) )

    {

      total += ( decimal )row.Cells[ "Freight" ].Value;

    }

    total = total / averageRow.ParentGroup.GetSortedDataRowCount( false );

    total = Math.Round( total, 3 );

    averageRow.Text = "The average freight for this group is " + total.ToString();

  }

  catch( Exception exception )

  {

    MessageBox.Show( exception.ToString() );

  }

}

// If you no longer wish to handle the SiblingDataRowsChangedevents that are raised,

// you can unsubscribe from the event notification by doing the following:

textRow1.SiblingDataRowsChanged -= new EventHandler( this.textRow1_SiblingDataRowsChanged );