dev 根据datatable动态生成gridview

简介: /// <summary> /// 根据datatable动态生成gridview /// </summary> /// <param name="dt"> code列是数据源,name列是显示名称</param> /// <param name="gv"><
 /// <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);
            }
        }

相关文章
|
JavaScript 数据库
EasyUI_datagrid实现动态加载列并为其绑定数据
EasyUI_datagrid实现动态加载列并为其绑定数据
678 0
|
数据建模 .NET 开发框架
C#-DataTable分页代码
/// /// DataTable分页并取出指定页码的数据 /// /// DataTable /// 页码,注意:从1开始 /// 每页条数 /// 指定页码的Dat...
1183 0
dev 根据datatable动态生成gridview
/// &lt;summary&gt; /// 根据datatable动态生成gridview /// &lt;/summary&gt; /// &lt;param name="dt"&gt; code列是数据源,name列是显示名称&lt;/param&gt; /// &lt;param name="gv"&gt;&lt;/p
48410 0