flexgrid中cell的合并问题
flexgrid中,我需要两行两行的合并,现在设置allowmerge是自动把相同的合并了,实际是需要分成5块合并上面贴的代码只是一个自定义合并的示例,具体到你这边的合并,可以这样写
public CellRange GetMergedRange(C1FlexGrid grid, CellType cellType, CellRange rg)
{
// we are only interested in data cells
// (not merging row or column headers)
if (cellType == CellType.Cell)
{
if (rg.Column == 1)
{
if (rg.Row % 2 == 0)
{
rg.Row2 = rg.Row + 1;
grid = grid==null?"": grid;
}
else
{
rg.Row = rg.Row - 1;
}
}
}
// done
return rg;
} 通过自定义合并可以实现
https://www.grapecity.com/blogs/flexgrid-migration-to-wpf-and-silverlight
// activate custom merge manager
flex.AllowMerging = AllowMerging.All;
flex.MergeManager = new MyMergeManager();
/// <summary>
/// Custom merge manager that creates cell ranges spanning multiple rows and columns
/// </summary>
public class MyMergeManager : IMergeManager
{
public CellRange GetMergedRange(C1FlexGrid grid, CellType cellType, CellRange rg)
{
// we are only interested in data cells
// (not merging row or column headers)
if (cellType == CellType.Cell)
{
// expand left/right
for (int i = rg.Column; i < grid.Columns.Count - 1; i++)
{
if (GetDataDisplay(grid, rg.Row, i) != GetDataDisplay(grid, rg.Row, i + 1)) break;
rg.Column2 = i + 1;
}
for (int i = rg.Column; i > 0; i--)
{
if (GetDataDisplay(grid, rg.Row, i) != GetDataDisplay(grid, rg.Row, i - 1)) break;
rg.Column = i - 1;
}
// expand up/down
for (int i = rg.Row; i < grid.Rows.Count - 1; i++)
{
if (GetDataDisplay(grid, i, rg.Column) != GetDataDisplay(grid, i + 1, rg.Column)) break;
rg.Row2 = i + 1;
}
for (int i = rg.Row; i > 0; i--)
{
if (GetDataDisplay(grid, i, rg.Column) != GetDataDisplay(grid, i - 1, rg.Column)) break;
rg.Row = i - 1;
}
}
// done
return rg;
}
string GetDataDisplay(C1FlexGrid grid, int r, int c)
{
return grid.ToString();
}
}
好像不行啊,我是要实现两行两行的合并 搞定了,谢谢 好的
页:
[1]