多个表格使用相同列信息时,需要分别添加列信息,不能使用同一个列对象,再创建一个新对象进行添加,否则只能操作一个表格信息
int index = 0; List<GridColumn> ColumnList = new List<GridColumn>(); ColumnList.Add(new GridColumn() { VisibleIndex = index++, Width = 150, FieldName = "CinemaName", Caption = "影院", Name = "CinemaName", Fixed = FixedStyle.Left }); ColumnList.Add(new GridColumn() { VisibleIndex = index++, Width = 80, FieldName = "City", Name = "City", Caption = "城市", Fixed = FixedStyle.Left }); ColumnList.Add(new GridColumn() { VisibleIndex = index++, Width = 80, FieldName = "PointCode", Name = "PointCode", Caption = "点位编号", Fixed = FixedStyle.Left }); ColumnList.Add(new GridColumn() { VisibleIndex = index++, Width = 60, FieldName = "PointType", Name = "PointType", Caption = "点位类型" }); ColumnList.Add(new GridColumn() { VisibleIndex = index++, Width = 60, FieldName = "MediaType", Name = "MediaType", Caption = "媒体形式" }); foreach (GridColumn item in ColumnList) { if (item.Name != "CinemaName") { item.OptionsColumn.AllowMerge = DevExpress.Utils.DefaultBoolean.False; } gridView1.Columns.Add(item); GridColumn col = new GridColumn() { VisibleIndex = item.VisibleIndex, Width = item.Width, FieldName = item.FieldName, Caption = item.Caption, Name = item.Name, Fixed = item.Fixed }; col.OptionsColumn.AllowMerge = item.OptionsColumn.AllowMerge; gridView2.Columns.Add(col); }