/// <summary> /// 绑定数据后,分配各列的宽度 /// </summary> private void GridView1_DataSourceChanged(object sender, EventArgs e) { if (this.winGridViewPager1.gridView1.Columns.Count > 0 && this.winGridViewPager1.gridView1.RowCount > 0) { //统一设置100宽度 foreach (DevExpress.XtraGrid.Columns.GridColumn column in this.winGridViewPager1.gridView1.Columns) { column.Width = 100;
column.AppearanceCell.TextOptions.HAlignment = HorzAlignment.Center;//列内容字体居中
column.AppearanceHeader.TextOptions.HAlignment = HorzAlignment.Center; //列头文字居中
} //可特殊设置特别的宽度 SetGridColumWidth("XM", 60); SetGridColumWidth("KCBH", 60); SetGridColumWidth("ZJHM", 150); SetGridColumWidth("KSCX", 60); SetGridColumWidth("KSYY", 60); SetGridColumWidth("YYCS", 60); SetGridColumWidth("JGFS1", 60); SetGridColumWidth("JGFS2", 60); SetGridColumWidth("KSCS", 60); SetGridColumWidth("KSY1", 60); SetGridColumWidth("KSY2", 60); SetGridColumWidth("SFPRINT", 60); SetGridColumWidth("KSJG", 60); SetGridColumWidth("KFXX1", 140); SetGridColumWidth("KFXX2", 140); } } private void SetGridColumWidth(string columnName, int width) { DevExpress.XtraGrid.Columns.GridColumn column = this.winGridViewPager1.gridView1.Columns.ColumnByFieldName(columnName); if (column != null) { column.Width = width; } }