开发者

Is there a way for GridColumns to inherrit a default set of Appearance settings from their parent GridView?

I have a GridView that gets GridColumns added to it dynamically. At design time, I don't know how many columns the view is going to have.

What I currently do to format each of these dynamically added columns, is format them i开发者_开发技巧n a foreach after the datasource of the grid has been set:

 foreach (GridColumn gridColumn in gridView.Columns)
        {
            gridColumn.AppearanceCell.Options.UseTextOptions = true;
            gridColumn.AppearanceCell.TextOptions.HAlignment = DevExpress.Utils.HorzAlignment.Center;
            gridColumn.AppearanceHeader.Options.UseTextOptions = true;
            gridColumn.AppearanceHeader.TextOptions.HAlignment = DevExpress.Utils.HorzAlignment.Near;
            gridColumn.AppearanceHeader.TextOptions.WordWrap = DevExpress.Utils.WordWrap.Wrap;
            gridColumn.OptionsColumn.AllowGroup = DevExpress.Utils.DefaultBoolean.False;
            gridColumn.OptionsColumn.AllowIncrementalSearch = false;
            gridColumn.OptionsColumn.AllowMerge = DevExpress.Utils.DefaultBoolean.False;
            gridColumn.OptionsColumn.AllowMove = false;
            gridColumn.OptionsColumn.AllowSort = DevExpress.Utils.DefaultBoolean.False;
            gridColumn.OptionsColumn.AllowEdit = false;
        }

The problem is I may have a large number of columns and this foreach is slowing down my initial drawing. Isn't there a way to decide, for the GridView, how each of its columns are going to look, whether they have been added yet or not?


Change your code as shown below:

gridControl.BeginUpdate();
try { 
  // your code to change column appearances
}
finally { 
  gridControl.EndUpdate();
}

This will significantly improve the grid's performance :)


Regarding your comment (that I take to be a request for more information), you can use the RestoreLayoutFromStream() and SaveLayoutToStream() method to save your settings in the same way you save them to XML.

Just create a Stream property for your class and direct DevExpress to save that stream to that object.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜