KB Article A1963
Visible to All Users

How to determine DataRow objects which correspond to a particular Group row

Description:
I would like to be able to determine which DataRow objects correspond to the records in a particular group. How can I do this?

Answer:
First, we should mention that it is impossible to just call the GetRow or GetDataRow method to obtain the DataRow object corresponding to a particular Group row. This is because a group row does not correspond to any DataRow object - group rows are specially created by the grid to visualize grouping only. You can easily distinguish between a group row and a data row by the value returned by the view's FocusedRowHandle property. For group rows it's negative.
The XtraGrid provides the GridView.GetChildRowCount and GridView.GetChildRowHandle methods which allow you to iterate through the child records in a group row and determine their rowhandles. Using these values you will be able to convert them into DataRow objects using either the GridView.GetDataRow or GridView.GetRow methods. Here is some sample code showing how this can be done:

C#
private DataRow[] GetChildDataRows(GridView view, int rowHandle) { if(rowHandle >= 0) return null; ArrayList r = new ArrayList(); GetChildDataRows(view, rowHandle, r); DataRow[] result = new DataRow[r.Count]; r.CopyTo(result); return result; } void GetChildDataRows(GridView view, int rowHandle, ArrayList r) { int childCount = view.GetChildRowCount(rowHandle); for(int i = 0; i < childCount; i++){ int childRowHandle = view.GetChildRowHandle(rowHandle, i); if(childRowHandle < 0) GetChildDataRows(view, childRowHandle, r); else r.Add(view.GetDataRow(childRowHandle)); } }

See also:
How to traverse grid rows in their visible order
ms-help://MS.VSCC/DevExpress/DevExpress.XtraGrid/CustomDocument742.htm

Disclaimer: The information provided on DevExpress.com and affiliated web properties (including the DevExpress Support Center) is provided "as is" without warranty of any kind. Developer Express Inc disclaims all warranties, either express or implied, including the warranties of merchantability and fitness for a particular purpose. Please refer to the DevExpress.com Website Terms of Use for more information in this regard.

Confidential Information: Developer Express Inc does not wish to receive, will not act to procure, nor will it solicit, confidential or proprietary materials and information from you through the DevExpress Support Center or its web properties. Any and all materials or information divulged during chats, email communications, online discussions, Support Center tickets, or made available to Developer Express Inc in any manner will be deemed NOT to be confidential by Developer Express Inc. Please refer to the DevExpress.com Website Terms of Use for more information in this regard.