Back to Devexpress

How to: Save a View's Layout to and Restore it from a Stream

windowsforms-3042-controls-and-libraries-data-grid-examples-miscellaneous-how-to-save-a-views-layout-to-and-restore-it-from-a-stream.md

latest1.6 KB
Original Source

How to: Save a View's Layout to and Restore it from a Stream

  • Aug 01, 2019

Tip

You can utilize the Persistence Behavior or Workspace Manager component to save and restore layouts for all supported DevExpress controls at once.

The following sample code saves the layout of the active View to a memory stream and then restores it. The BaseView.SaveLayoutToStream and BaseView.RestoreLayoutFromStream methods are used for this purpose.

csharp
System.IO.Stream str;
//...
// Create and save the view's layout to a new memory stream.
str = new System.IO.MemoryStream();
gridControl1.FocusedView.SaveLayoutToStream(str);
str.Seek(0, System.IO.SeekOrigin.Begin);

// ...
// Load the view's layout from a previously saved memory stream.
gridControl1.FocusedView.RestoreLayoutFromStream(str);
str.Seek(0, System.IO.SeekOrigin.Begin);
vb
Dim str As System.IO.Stream
'...
' Create and save the view's layout to a new memory stream.
str = New System.IO.MemoryStream()
GridControl1.FocusedView.SaveLayoutToStream(str)
str.Seek(0, System.IO.SeekOrigin.Begin)

' ...
' Load the view's layout from a previously saved memory stream.
GridControl1.FocusedView.RestoreLayoutFromStream(str)
str.Seek(0, System.IO.SeekOrigin.Begin)