現在要在DevExpress 的GridView 中實現這樣一個功能。就是判斷當前的選中行是否是分組行,如果是的話就要獲取該分組下的所有數據信息。
如下圖(當選中紅框中的分組行事。程序要獲取該分組下的所有數據)

實現代碼如下:
List<int> _gridViewRowIndexs = new List<int>(); //存儲GridView 中選中的行索引
private void Test()
{
int[] rows = gridView1.GetSelectedRows(); //獲取GridView 選中的數據行信息
for (int i = 0; i < rows.Count(); i++)
_gridViewRowIndexs = FildRowsNotGroupIndex(rows[i]);
}
//獲取分組下面的所有數據行索引(針對有多級分組的情況)
private List<int> FildRowsNotGroupIndex(int rowIndex)
{
List<int> returnValue = new List<int>();
bool isGroup = gridView1.IsGroupRow(rowIndex);//判斷當前的行索引是否是分組行
if (isGroup == false)
{
returnValue.Add(rowIndex);
}
else
{
int count = gridView1.GetChildRowCount(rowIndex);//獲取當前分組下的數據個數
for (int j = 0; j < count; j++)
{
int childRowIndex = gridView1.GetChildRowHandle(rowIndex, j);//獲取當前分組下的第i條記錄的行索引
returnValue.AddRange(FildRowsNotGroupIndex(childRowIndex).ToArray());
}
}
return returnValue;
}
獲取的行索引_gridViewRowIndexs 是GridView 中的行索引。如果要獲取綁定數據源的行索引。
int dataTableIndex = gridView1.GetDataSourceRowIndex(item); //將 GridView 中的行索引轉化成 綁定數據源中的行索引
