2X faster development
The ultimate WinForms UI toolkit to boost your development speed.
Save column order and column widthWhen a GridControl has serialization support through its GridModel.LoadBinary / GridModel.SaveBinary or GridModel.LoadSoap / GridModel.SaveSoap. Currently this is not supported in GridDataBoundGrid. When you want to save column position and widths, then use .NET Frameworks serialization support. C# void Form1_FormClosing(object sender, FormClosingEventArgs e) { try { //Serialize out the row heights & column widths IFormatter formatter = new BinaryFormatter(); Stream stream = new FileStream("MySizes.bin", FileMode.Create, FileAccess.Write, FileShare.None); //Handle the mapping names GridBoundColumnsCollection col = (GridBoundColumnsCollection)this.gridDataBoundGrid1.GridBoundColumns; if(col.Count == 0) col = this.gridDataBoundGrid1.Binder.InternalColumns; int nCols = col.Count; string[] a = new string[nCols]; int i = 0; foreach (GridBoundColumn c in col) a[i++] = c.MappingName; formatter.Serialize(stream, a); formatter.Serialize(stream, this.gridDataBoundGrid1.Model.ColWidths.Dictionary); stream.Close(); } catch (Exception ex) { } } private void Form1_Load(object sender, EventArgs e) { initializegrid(); } public void initializegrid() { if (File.Exists("MySizes.bin")) { try { IFormatter formatter = new BinaryFormatter(); Stream stream = new FileStream("MySizes.bin", FileMode.Open, FileAccess.Read, FileShare.None); try { this.gridDataBoundGrid1.BeginUpdate(); //handle the mappingnames GridBoundColumnsCollection col = (GridBoundColumnsCollection)this.gridDataBoundGrid1.GridBoundColumns.Clone(); if (col.Count == 0) col = this.gridDataBoundGrid1.Binder.InternalColumns; string[] a = (string[])formatter.Deserialize(stream); this.gridDataBoundGrid1.GridBoundColumns.Clear(); foreach (string s in a) { GridBoundColumn c = col[s]; this.gridDataBoundGrid1.GridBoundColumns.Add(c); } this.gridDataBoundGrid1.Model.ColWidths.Dictionary = (Syncfusion.Windows.Forms.Grid.GridRowColSizeDictionary)formatter.Deserialize(stream); } finally { this.gridDataBoundGrid1.EndUpdate(); this.gridDataBoundGrid1.Refresh(); stream.Close(); } } catch (Exception ex) { } } } VB Private Sub Form1_FormClosing(ByVal sender As Object, ByVal e As FormClosingEventArgs) Try 'Serialize out the row heights & column widths Dim formatter As IFormatter = New BinaryFormatter() Dim stream As Stream = New FileStream("MySizes.bin", FileMode.Create, FileAccess.Write, FileShare.None) 'Handle the mapping names Dim col As GridBoundColumnsCollection = CType(Me.gridDataBoundGrid1.GridBoundColumns, GridBoundColumnsCollection) If col.Count = 0 Then col = Me.gridDataBoundGrid1.Binder.InternalColumns End If Dim nCols As Integer = col.Count Dim a(nCols - 1) As String Dim i As Integer = 0 For Each c As GridBoundColumn In col a(i) = c.MappingName i += 1 Next c formatter.Serialize(stream, a) formatter.Serialize(stream, Me.gridDataBoundGrid1.Model.ColWidths.Dictionary) stream.Close() Catch ex As Exception End Try End Sub Private Sub Form1_Load(ByVal sender As Object, ByVal e As EventArgs) initializegrid() End Sub Public Sub initializegrid() If File.Exists("MySizes.bin") Then Try Dim formatter As IFormatter = New BinaryFormatter() Dim stream As Stream = New FileStream("MySizes.bin", FileMode.Open, FileAccess.Read, FileShare.None) Try Me.gridDataBoundGrid1.BeginUpdate() 'handle the mappingnames Dim col As GridBoundColumnsCollection = CType(Me.gridDataBoundGrid1.GridBoundColumns.Clone(), GridBoundColumnsCollection) If col.Count = 0 Then col = Me.gridDataBoundGrid1.Binder.InternalColumns End If Dim a() As String = CType(formatter.Deserialize(stream), String()) Me.gridDataBoundGrid1.GridBoundColumns.Clear() For Each s As String In a Dim c As GridBoundColumn = col(s) Me.gridDataBoundGrid1.GridBoundColumns.Add(c) Next s Me.gridDataBoundGrid1.Model.ColWidths.Dictionary = CType(formatter.Deserialize(stream), Syncfusion.Windows.Forms.Grid.GridRowColSizeDictionary) Finally Me.gridDataBoundGrid1.EndUpdate() Me.gridDataBoundGrid1.Refresh() stream.Close() End Try Catch ex As Exception End Try End If End Sub Samples: |
2X faster development
The ultimate WinForms UI toolkit to boost your development speed.
This page will automatically be redirected to the sign-in page in 10 seconds.