views:

50

answers:

2

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 in 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?

A: 

Hi,

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 :)

DevExpress Team
Thanks, this increases the loading by about 5 times, but I still it think it would make a lot more sense to decide how any columns of a view should look and behave in a templatised way.
Corpsekicker
A: 

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.

George Stocker