我有一个包含多个组的gridview,我使用CustomDrawGroupRow
事件显示每个组的行数:
private void gridView_CustomDrawGroupRow(object sender, DevExpress.XtraGrid.Views.Base.RowObjectCustomDrawEventArgs e)
{
var view = (GridView)sender;
var info = (GridGroupRowInfo)e.Info;
var caption = info.Column.Caption;
if (info.Column.Caption == string.Empty)
{
caption = info.Column.ToString();
}
info.GroupText = $"{caption} : {info.GroupValueText} ({view.GetChildRowCount(e.RowHandle)})";
}
现在我想以递归方式显示行数,以便第一级显示计数为2171(1913 + 135 + 123)。
这是我尝试过的,但它会抛出 StackOverflowException ,我在这里看不到问题:
private void gridView_CustomDrawGroupRow(object sender, DevExpress.XtraGrid.Views.Base.RowObjectCustomDrawEventArgs e)
{
var view = (GridView)sender;
var info = (GridGroupRowInfo)e.Info;
var caption = info.Column.Caption;
if (info.Column.Caption == string.Empty)
{
caption = info.Column.ToString();
}
info.GroupText = $"{caption} : {info.GroupValueText} ({GetRowCountRecursive(view, e.RowHandle)})";
}
private int GetRowCountRecursive(GridView view, int rowHandle)
{
int totalCount = 0;
int childrenCount = view.GetChildRowCount(rowHandle);
for (int i = 0; i < childrenCount; i++)
{
var childRowHandle = view.GetChildRowHandle(rowHandle, i);
totalCount += GetRowCountRecursive(view, childRowHandle);
}
return totalCount;
}
答案 0 :(得分:2)
我错过了检查def length_even(array)
half = array[(0...array.length/2)]
count = 0
half.each do |x|
array << x
count+=1
end
p array.drop(count).join
end
是否为childRowHandle
的群组行。如果不是,则递归必须停止并且IsGroupRow()
需要增加1。
totalCount
答案 1 :(得分:1)
您可以使用GroupRowInfo.ChildControllerRowCount
属性来获取行数。您可以从GroupRowInfo
属性获取GridGroupRowInfo.RowKey
课程的实例
这是一个例子:
private void gridView1_CustomDrawGroupRow(object sender, RowObjectCustomDrawEventArgs e)
{
var view = (GridView)sender;
var info = (GridGroupRowInfo)e.Info;
var caption = info.Column.Caption;
if (info.Column.Caption == string.Empty)
{
caption = info.Column.ToString();
}
var groupInfo = info.RowKey as GroupRowInfo;
info.GroupText = $"{caption} : {info.GroupValueText} ({groupInfo?.ChildControllerRowCount})";
}