DevExpress.XtraEditors.GridLookUpEdit 隐藏列

第三方控件中,我们经常用GridLookUpEdit来下拉多条数据,有时候需要隐藏某一列,在9.2之前

Title            this.gle1.Properties.DataSource = dt;
            this.gle1.Properties.ValueMember = "Column1";
            this.gle1.Properties.DisplayMember = "Column2";
            this.gle1.Properties.View.Columns["Column1"].Visible = false;

 

这样做,指定列就可以了,但是当控件升级到11.2后,发现Columns里面是没有值的,必须手动赋上列值

Title            this.gle1.Properties.DataSource = dt;
            this.gle1.Properties.ValueMember = "column1";
            this.gle1.Properties.DisplayMember = "column2";
            string tempStr = string.Empty;  //列名
            this.gle1.Properties.View.Columns.Clear();
            for (int i = 0; i < dt.Columns.Count; i++) {
                tempStr = dt.Columns[i].ColumnName;
                DevExpress.XtraGrid.Columns.GridColumn col = this.gle1.Properties.View.Columns.AddField(tempStr);
                col.VisibleIndex = i;
                col.Caption = tempStr;

                if (tempStr.Equals("column1"))
                    col.Visible = false;
            }     

感觉上这种写法有点丑陋,不知道有没有更好的方法。
posted @ 2012-06-01 10:09  浪潮  阅读(2586)  评论(1编辑  收藏  举报