UltraWinGrid 动态实现多级多表头


using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms; using Infragistics.Win; using Infragistics.Win.UltraWinGrid; namespace ultragridDemo { public partial class Form1 : Form { public Form1() { InitializeComponent(); } private void Form1_Load(object sender, EventArgs e) { //新版本用下面的 this.ultraGrid1.DisplayLayout.Bands[0].RowLayoutStyle = RowLayoutStyle.GroupLayout; //旧版本用下面的 //this.ultraGrid1.DisplayLayout.Bands[0].UseRowLayout = true; this.ultraGrid1.DisplayLayout.Override.AllowRowLayoutColMoving = Infragistics.Win.Layout.GridBagLayoutAllowMoving.AllowAll; modifyColumn("4", "测试4", 0, 0, 2, 1); modifyColumn("1", "测试1", 0, 1, 1, 2); modifyColumn("2", "测试2", 1, 1, 1, 1); modifyColumn("3", "测试3", 1, 2, 1, 1); //不需要显示单元格的列,单纯当表头显示的列 this.ultraGrid1.DisplayLayout.Bands[0].Columns["2"].RowLayoutColumnInfo.LabelPosition = LabelPosition.LabelOnly; this.ultraGrid1.DisplayLayout.Bands[0].Columns["4"].RowLayoutColumnInfo.LabelPosition = LabelPosition.LabelOnly; DataTable dt = new DataTable(); dt.Columns.Add("1", typeof(string)); dt.Columns.Add("3", typeof(string)); dt.Rows.Add("as", "why"); dt.Rows.Add("test", "test1"); ultraGrid1.DataSource = dt; ultraGrid1.DataBind(); } /// <summary> /// 合并表头函数 /// </summary> /// <param name="columnName">列名</param> /// <param name="caption">表头名</param> /// <param name="x">表头横轴起始点</param> /// <param name="y">表头纵轴起始点</param> /// <param name="spanX">横向跨度</param> /// <param name="spanY">纵向跨度</param> private void modifyColumn(string columnName, string caption, int x, int y, int spanX, int spanY) { this.ultraGrid1.DisplayLayout.Bands[0].Columns.Add(columnName); UltraGridColumn GridColumn = this.ultraGrid1.DisplayLayout.Bands[0].Columns[columnName]; GridColumn.Header.Caption = caption; GridColumn.Header.Appearance.TextVAlign = Infragistics.Win.VAlign.Middle; GridColumn.Header.Appearance.TextHAlign = Infragistics.Win.HAlign.Center; GridColumn.RowLayoutColumnInfo.OriginX = x; GridColumn.RowLayoutColumnInfo.OriginY = y; GridColumn.RowLayoutColumnInfo.SpanX = spanX; GridColumn.RowLayoutColumnInfo.SpanY = spanY; //GridColumn.CellActivation = Activation.Disabled; GridColumn.RowLayoutColumnInfo.AllowCellSizing = RowLayoutSizing.None; GridColumn.SortIndicator = SortIndicator.Disabled; } } }

评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值