子行も含んだ全ての行をループさせる効率的な方法は再帰呼び出しを使用することです。このトピックでは実際の実装として、TraverseAllRowsHelper を実装します。
using Infragistics.Win.UltraWinGrid;
using System;
using System.Data;
using System.Windows.Forms;
private void button1_Click(object sender, EventArgs e)
{
int rowsCount = 0;
int groupByRowsCount = 0;
// ヘルパーメソッドを呼び出します
TraverseAllRowsHelper(this.ultraGrid1.Rows, ref rowsCount, ref groupByRowsCount);
MessageBox.Show("UltraGrid の行数: " + rowsCount.ToString() + " グループ化行: " + groupByRowsCount.ToString());
}
private void TraverseAllRowsHelper(RowsCollection rows, ref int rowsCount, ref int groupByRowsCount)
{
foreach (UltraGridRow row in rows)
{
if (row is UltraGridGroupByRow)
{
UltraGridGroupByRow groupByRow = (UltraGridGroupByRow)row;
groupByRowsCount++;
}
else
{
rowsCount++;
}
if (null != row.ChildBands)
{
foreach (UltraGridChildBand childBand in row.ChildBands)
{
this.TraverseAllRowsHelper(childBand.Rows, ref rowsCount, ref groupByRowsCount);
}
}
}
}
サンプル