WPF的C1FlexGrid控件合并相同列

<c1:C1FlexGrid Name="CfgRiskReviewItem" Style="{StaticResource Green}" ItemsSource="{Binding RiskReviewList,Mode=TwoWay}" SelectedItem="{Binding CurrentRiskReviewItem,Mode=TwoWay}"

LoadedRows="FlexGrid_LoadedRiskReviewRows_RowIndex" PreviewKeyDown="c1FlexGrid_PreviewKeyDown" MinRowHeight="50" Margin="5,5,5,0" AllowMerging="Cells"

表格增加AllowMerging="Cells"属性

cs代码初始化方法里面写上

CfgRiskReviewItem.CellFactory = new FlexGridShowCellFactory();

CfgRiskReviewItem.MergeManager = new SummaryProjectMergeManager();

private class SummaryProjectMergeManager : IMergeManager

{

/// <summary>

/// 获取合并块

/// </summary>

/// <param name="grid"></param>

/// <param name="cellType"></param>

/// <param name="rg"></param>

/// <returns></returns>

public CellRange GetMergedRange(C1FlexGrid grid, CellType cellType, CellRange rg)

{

var colName = grid.Columnsrg.Column.ColumnName;

if (cellType != CellType.Cell)

{

return rg;

}

switch (colName)

{

case "RiskName":

return SetRg(grid, rg, new List<string>() { colName });

// case "item2":

// return SetGeCg(grid, rg, new List<string>() { colName });

default:

return rg;

}

}

/// <summary>

/// 设置合并块

/// </summary>

/// <param name="grid"></param>

/// <param name="rg"></param>

/// <param name="depColList">合并依据列</param>

/// <returns></returns>

private CellRange SetRg(C1FlexGrid grid, CellRange rg, List<string> depColList)

{

for (int i = rg.Row; i < grid.Rows.Count - 1; i++)

{

bool isSame = true;

foreach (var depCol in depColList)

{

if (GetDataDisplay(grid, i, grid.ColumnsdepCol.Index) != GetDataDisplay(grid, i + 1, grid.ColumnsdepCol.Index))

{

isSame = false;

break;

}

}

if (!isSame)

{

break;

}

rg.Row2 = i + 1;

}

for (int i = rg.Row; i > 0; i--)

{

bool isSame = true;

foreach (var depCol in depColList)

{

if (GetDataDisplay(grid, i, grid.ColumnsdepCol.Index) != GetDataDisplay(grid, i - 1, grid.ColumnsdepCol.Index))

{

isSame = false;

break;

}

}

if (!isSame)

{

break;

}

rg.Row = i - 1;

}

return rg;

}

private CellRange SetGeCg(C1FlexGrid grid, CellRange rg, List<string> depColList)

{

for (int i = rg.Row; i < grid.Rows.Count - 1; i++)

{

if (i == 6)

{

grid6, 6 = null;

grid6, 7 = null;

grid6, 8 = null;

grid.Rowsi.AllowMerging = true;

break;

}

}

return rg;

}

/// <summary>

/// 获取单元格显示值

/// </summary>

/// <param name="grid"></param>

/// <param name="r"></param>

/// <param name="c"></param>

/// <returns></returns>

private string GetDataDisplay(C1FlexGrid grid, int r, int c)

{

return (gridr, c ?? "").ToString();

}

}

效果

相关推荐
小羊没烦恼!20 小时前
分布式事务 | 使用DTM 的Saga 模式
java·linux·运维·数据库·wpf
samble2 天前
从零搭建半导体设备上位机(二):Prism + DryIoc,五个工程与区域导航怎么串起来
wpf·prism·dryioc
一条闲鱼_mytube2 天前
分布式 ID 生成方案:雪花算法与号段模式
分布式·算法·wpf
她说彩礼65万2 天前
WPF Prism代码走读
wpf
光泽雨5 天前
动画生命周期
c#·wpf
nap1176 天前
WPF 中常用的 LINQ 语句
wpf
做个文艺程序员9 天前
MQ第12篇:AI原生消息架构演进:从MQ到事件驱动的全链路设计
架构·消息队列·wpf·事件驱动架构·ai-native·cqrs
donk131411 天前
React Native for OpenHarmony 实战:三方库 react-native-circular-action-menu 的鸿蒙化适配指南
javascript·分布式·react native·react.js·wpf·harmonyos
donk131412 天前
React Native for OpenHarmony 实战:三方库 react-native-step-indicator 的鸿蒙化适配指南
分布式·react native·react.js·wpf·harmonyos