Xceed Grid for WinForms v4.3 Documentation
How to iterate through the grid's rows

Welcome to Xceed Grid for WinForms v4.3 > Task-Based Help > Rows > How to iterate through the grid's rows

There is no direct way you can iterate through all the rows in the grid in a sequential manner. In order to iterate through all of the grid's rows, you will need to go through each collection of rows. 

Collection Description
GridControl.FixedHeaderRows A list of all the fixed header rows of the grid. The fixed header rows are the rows found in the non-scrollable header section of the grid. This section will not scroll with the grid body.
GridControl.HeaderRows A list of all the non-fixed header rows of the grid. The header rows are the rows found in the header section of the grid, before the data rows and groups, and that scroll with the grid body.

Group.HeaderRows

A list of all the header rows of the group. The header rows are the rows found in the header section of the group, before the data rows.

Group.GetSortedDatarows

A collection of sorted data rows.

Group.FooterRows

A list of all the footer rows of the group. The footer rows are the rows found in the footer section of the group, after the data rows.

GridControl.DataRows or

GridControl.GetSortedDataRows

A list of all the data rows in the grid.

GridControl.FooterRows A list of all the non-fixed footer rows of the grid. The footer rows are the rows found in the footer section of the grid, after the data rows and groups, and that scroll with the grid body.
GridControl.FixedFooterRows A list of all the fixed footer rows of the grid. The fixed footer rows are the rows found in the non-scrollable footer section of the grid. This section will not scroll with the grid body.

The GetSortedDataRows methods of either the grid or a group will return a collection containing the DataRows in the order that they are sorted. If a group contains child groups, it will not have any immediate child DataRows.

Demonstration

The following example demonstrates how to iterate through all the rows found in the grid and display information about each in a listbox.

VB.NET Copy Code
Dim row As Row

For Each row In GridControl1.FixedHeaderRows
   ListBox1.Items.Add( "FixedHeaderRows : " + row.GetType().ToString() )
Next row

For Each row In GridControl1.HeaderRows
   ListBox1.Items.Add( "HeaderRows : " + row.GetType().ToString() )
Next row

If GridControl1.Groups.Count > 0 Then
   Dim group As Group

   For Each group In GridControl1.Groups
      Me.ListDataRows( group )
   Next group
Else ' There are no groups so we will simply list the DataRows
   For Each row In GridControl1.DataRows
      ListBox1.Items.Add( "DataRows : " + row.GetType().ToString() )
   Next row
End If

For Each row In GridControl1.FooterRows
   ListBox1.Items.Add( "FooterRows : " + row.GetType().ToString() )
Next row

For Each row In GridControl1.FixedFooterRows
   ListBox1.Items.Add( "FixedFooterRows : " + row.GetType().ToString() )
Next row    

Private Sub ListDataRows( ByVal group As Group )
   If group.Groups.Count > 0 Then
      Dim childGroup As Group
      For Each childGroup In group.Groups
         Me.ListDataRows( childGroup )
      Next childGroup
   Else

      Dim row As Xceed.Grid.DataRow
      For Each row In group.GetSortedDataRows( false )
         ListBox1.Items.Add( "Group level #" + group.Level.ToString() + " : " + _
                             row.GetType().ToString() )      
      Next row
   End If
End Sub                  
C# Copy Code
foreach( Row row in gridControl1.FixedHeaderRows )
   listBox1.Items.Add( "FixedHeaderRows : " + row.GetType().ToString() ); 

foreach( Row row in gridControl1.HeaderRows )
   listBox1.Items.Add( "HeaderRows : " + row.GetType().ToString() );
   if( gridControl1.Groups.Count > 0 )
   {
      foreach( Group group in gridControl1.Groups )
         this.ListDataRows( group );
   }
   else // There are no groups so we will simply list the DataRows
   {
      foreach( Row row in gridControl1.DataRows )
         listBox1.Items.Add( "DataRows : " + row.GetType().ToString() );
   }

   foreach( Row row in gridControl1.FooterRows )
      listBox1.Items.Add( "FooterRows : " + row.GetType().ToString() );

   foreach( Row row in gridControl1.FixedFooterRows )
      listBox1.Items.Add( "FixedFooterRows : " + row.GetType().ToString() );

private void ListDataRows( Group group )
{
   if( group.Groups.Count > 0 )
   {
      foreach( Group childGroup in group.Groups )
      {
         this.ListDataRows( childGroup );
      }
   }
   else
   {
      foreach( Xceed.Grid.DataRow row in group.GetSortedDataRows( false ) )
         listBox1.Items.Add( "Group level #" + group.Level.ToString() + " : " +
                             row.GetType().ToString() );
   }
}