
添加行或列的大纲分组:
// 从第3行开始分组5行(注意:aardio中行号从0开始)
sheet1.AddOutline(ReoGrid.RowOrColumn.Row, 3, 5);
// 从第5列开始分组2列
sheet1.AddOutline(ReoGrid.RowOrColumn.Column, 5, 2);
注意:AddOutline 方法可能会抛出以下异常:
AddOutline 方法会返回大纲对象实例,该对象有两个控制方法:
// 添加行大纲并获取实例
var outline = sheet1.AddOutline(ReoGrid.RowOrColumn.Row, 3, 5);
outline.Collapse(); // 折叠
outline.Expand(); // 展开
或者直接调用控件的 CollapseOutline 和 ExpandOutline 方法,通过位置参数指定要操作的大纲:
// 直接通过位置参数控制大纲
sheet1.CollapseOutline(ReoGrid.RowOrColumn.Row, 3, 5);
sheet1.ExpandOutline(ReoGrid.RowOrColumn.Row, 3, 5);
注意:当指定位置找不到对应大纲时,上述方法会抛出 OutlineNotFoundException 异常(本例中必须从第3行开始且行数为5)。
使用 RemoveOutline 方法移除指定大纲:
// 移除从第3行开始的行分组(5行)
sheet1.RemoveOutline(ReoGrid.RowOrColumn.Row, 3, 5);
注意:当指定位置找不到对应大纲时,RemoveOutline 会抛出 OutlineNotFoundException 异常。
另可使用 ClearOutlines 方法清除工作表中所有指定类型的大纲:
// 清除所有行分组大纲
sheet1.ClearOutlines(ReoGrid.RowOrColumn.Row);
当大纲的结束行被隐藏或行高设为0时,大纲会自动折叠;当被分组的行变为可见或行高恢复时,大纲会自动展开。此行为不可禁用,但会触发大纲的折叠/展开事件。

调整行高后:

当大纲关联的所有行或列被删除时,该大纲会自动移除。此行为不可禁用,但会触发 OutlineRemoved 事件。
当大纲被添加或移除时,会触发以下两个工作表事件:
// 添加大纲事件
sheet1.OutlineAdded = function(sender, e){
winform.msgbox("大纲已添加,范围:" + e.Outline.Start + " 到 " + e.Outline.End);
}
// 移除大纲事件
sheet1.OutlineRemoved = function(sender, e){
winform.msgbox("大纲已移除,范围:" + e.Outline.Start + " 到 " + e.Outline.End);
}
由于删除行会自动移除关联的大纲,此时也会触发 OutlineRemoved 事件:
// 删除行会触发关联大纲的移除事件
sheet1.DeleteRows(4, 5);
执行上述代码后,会显示消息:
大纲已移除,范围:5 到 3
大纲实例和工作表实例都提供了处理折叠/展开操作的事件:
// 添加列分组大纲
var outline = sheet1.AddOutline(ReoGrid.RowOrColumn.Column, 1, 3);
// 大纲实例事件
outline.BeforeCollapse = function(sender, e){
winform.msgbox("即将折叠");
}
outline.BeforeExpand = function(sender, e){
winform.msgbox("即将展开");
}
outline.AfterCollapse = function(sender, e){
winform.msgbox("已折叠");
}
outline.AfterExpand = function(sender, e){
winform.msgbox("已展开");
}
// 工作表实例事件
sheet1.BeforeOutlineCollapse = function(sender, e){
winform.msgbox("工作表 - 即将折叠");
}
sheet1.AfterOutlineCollapse = function(sender, e){
winform.msgbox("工作表 - 已折叠");
}
sheet1.BeforeOutlineExpand = function(sender, e){
winform.msgbox("工作表 - 即将展开");
}
sheet1.AfterOutlineExpand = function(sender, e){
winform.msgbox("工作表 - 已展开");
}
与其他 ReoGrid的"Before"事件类似,可以通过设置 IsCancelled 属性为 true 来取消操作:
// 通过设置 IsCancelled 取消折叠/展开操作
sheet1.BeforeOutlineCollapse = function(sender, e){
e.IsCancelled = true;
}
更多事件请参考事件文档。
可以隐藏大纲的用户界面,防止最终用户操作大纲。此时仍可通过编程方式控制大纲的折叠/展开:
// 禁用行列大纲的界面显示
sheet1.SetSettings(ReoGrid.WorksheetSettings.View_AllowShowOutlines, false);
// 添加大纲1并折叠
var outline1 = sheet1.AddOutline(ReoGrid.RowOrColumn.Row, 1, 3);
outline1.Collapse();
// 添加大纲2并折叠
var outline2 = sheet1.AddOutline(ReoGrid.RowOrColumn.Row, 5, 2);
outline2.Collapse();

如需重新显示大纲界面,将设置改为true即可:
// 启用大纲界面显示
sheet1.SetSettings(ReoGrid.WorksheetSettings.View_AllowShowOutlines, true);