DevExpress Add Column bug

摘要:DevExpress Add Column bug



虽然底下两种写法看起来应该一样, 但实际上结果不同, 看起来是DevExpress 的问题, 当column 加入到 GridView1以后, 再设定 DisplayFormat 似乎就没效了

状况1 : 这种写法时 DisplayFormat 设定值才会有效                


		DevExpress.XtraGrid.Columns.GridColumn col = new DevExpress.XtraGrid.Columns.GridColumn();

                col.AppearanceHeader.Font = new System.Drawing.Font("Tahoma", 9F, System.Drawing.FontStyle.Bold);
                col.AppearanceHeader.Options.UseFont = true; 
                
                col.Caption = stn;                
                col.DisplayFormat.FormatString = "{0:N2}";
                col.DisplayFormat.FormatType = DevExpress.Utils.FormatType.Numeric;
                col.FieldName = stn;
                col.Name = "gridColumnDy" + this.gridView1.Columns.Count.ToString();
                col.Visible = true;
                col.VisibleIndex = this.gridView1.Columns.Count ;
                
                this.gridView1.Columns.Add(col);

状况2 : 这种写法时 DisplayFormat 设定值没用


                DevExpress.XtraGrid.Columns.GridColumn col = this.gridView1.Columns.Add();

                col.AppearanceHeader.Font = new System.Drawing.Font("Tahoma", 9F, System.Drawing.FontStyle.Bold);
                col.AppearanceHeader.Options.UseFont = true; 
                
                col.Caption = stn;                
                col.DisplayFormat.FormatString = "{0:N2}";
                col.DisplayFormat.FormatType = DevExpress.Utils.FormatType.Numeric;
                col.FieldName = stn;
                col.Name = "gridColumnDy" + this.gridView1.Columns.Count.ToString();
                col.Visible = true;
                col.VisibleIndex = this.gridView1.Columns.Count ;