dev는 데이터테이블에 따라 gridview를 동적으로 생성합니다

 /// <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);
            }
        }

좋은 웹페이지 즐겨찾기