Dev GridView Winform 横竖合并单元格

本文介绍了如何在Dev GridView的Winform应用中实现单元格的横竖合并,提供了源码下载和具体的操作类实现,帮助开发者更好地理解和使用DevExpress表格控件。
摘要由CSDN通过智能技术生成

参考:传送门

源码下载地址:下载

以下源码:

待合并单元格对象

using System; using System.Collections.Generic; using System.Linq; using System.Text;

using DevExpress.XtraGrid.Columns; namespace MyUtil { public class MyMergedCell { public MyMergedCell(int rowHandle1, GridColumn col1,int rowHandle2,GridColumn col2) { RowHandle1 = rowHandle1; Column1 = col1; RowHandle2 = rowHandle2; Column2 = col2; } public int RowHandle1 { get; set; } public GridColumn Column1 { get; set; } public int RowHandle2 { get; set; } public GridColumn Column2 { get; set; } } }

重绘单元格操作类

using System; using System.Collections.Generic; using System.Linq; using System.Text;

using DevExpress.XtraGrid.Views.Grid.ViewInfo; using DevExpress.XtraGrid.Views.Grid; using DevExpress.XtraGrid.Views.Grid.Drawing; using DevExpress.Utils.Drawing; using System.Drawing; using System.Windows.Forms; namespace MyUtil { public class MyGridPainter:GridPainter { public MyGridPainter(GridView view):base(view) { } public bool IsCustomPainting { get; set; } public void DrawMergedCell(MyMergedCell cell,PaintEventArgs e) { int delta=cell.Column1.VisibleIndex - cell.Column2.VisibleIndex; int rowdelta = cell.RowHandle1 - cell.RowHandle2; if(Math.Abs(delta)>1||Math.Abs(rowdelta)>1) { return; } GridViewInfo vi=(GridViewInfo)View.GetViewInfo(); GridCellInfo gridCellInfo1=vi.GetGridCellInfo(cell.RowHandle1, cell.Column1.AbsoluteIndex); GridCellInfo gridCellInfo2=vi.GetGridCellInfo(cell.RowHandle2, cell.Column2.AbsoluteIndex); if(gridCellInfo1==null || gridCellInfo2==null) { return; } if (gridCellInfo1.IsMerged || gridCellInfo2.IsMerged) { return; } Rectangle targetRect=Rectangle.Union(gridCellInfo1.Bounds, gridCellInfo2.Bounds); gridCellInfo1.Bounds = targetRect; gridCellInfo1.CellValueRect = targetRect; gridCellInfo2.Bounds = targetRect; gridCellInfo2.CellValueRect = targetRect; if (delta < 0||rowdelta<0) { gridCellInfo1 = gridCellInfo2; } Rectangle bounds = gridCellInfo1.ViewInfo.Bounds; bounds.Width = targetRect.Width; bounds.Height = targetRect.Height; gridCellInfo1.ViewInfo.Bounds = bounds;

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值