/// <summary> /// 根据datatable动态生成gridview /// </summary> /// <param name="dt"> code列是数据源,name列是显示名称</param> /// <param name="gv"></param> private void GetDynamicView(DataTable dt, GridView gv) { //gv.IndicatorWidth = 40;//行号列宽度 //此处DataTable中有两列:code name if (dt != null) { foreach (DataRow dr in dt.Rows) { DevExpress.XtraGrid.Columns.GridColumn cl = new DevExpress.XtraGrid.Columns.GridColumn(); cl.Name = dr["Code"].ToString(); cl.Caption = dr["Name"].ToString(); cl.FieldName = dr["Code"].ToString(); cl.OptionsColumn.AllowSize = true; cl.OptionsColumn.ReadOnly = true; cl.OptionsColumn.AllowEdit = false; cl.OptionsColumn.AllowMove = false; cl.OptionsColumn.AllowSort = DevExpress.Utils.DefaultBoolean.False; cl.OptionsColumn.AllowGroup = DevExpress.Utils.DefaultBoolean.False; cl.OptionsFilter.AllowFilter = false; cl.OptionsFilter.AllowAutoFilter = false; cl.Visible = true; gv.Columns.Add(cl); } //gv.BestFitColumns(); gv.OptionsView.ColumnAutoWidth = true; //gv.CustomDrawEmptyForeground += new DevExpress.XtraGrid.Views.Base.CustomDrawEventHandler(this.gridView_CustomDrawEmptyForeground); //gv.MouseDown += new System.Windows.Forms.MouseEventHandler(this.gridView_MouseDown); //gv.CustomDrawRowIndicator += new DevExpress.XtraGrid.Views.Grid.RowIndicatorCustomDrawEventHandler(this.gridView_CustomDrawRowIndicator); } }
作者:jiankunking 出处:http://blog.csdn.net/jiankunking
时间: 2024-10-30 23:51:54