We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date
close icon

Saving grid properties for a GridDatabound

How would I go about saving (serializing) the grid's column order and column width at run time. Also where do I find the column width of a GridBoundColumn? Could I also suggest that when opening the property box for the GridBoundColumns collection, that the little explanatory note appears in the footer as well Thanks Jeremy

4 Replies

AD Administrator Syncfusion Team April 17, 2003 02:59 PM UTC

Here is a project that loads the customers table from the NorthWind database. As shipped, there is already a MySizes.bin file present in the debug folder. So, if you run it, it should display the grid as was last set by me. If you delete this file, and run things, it should display the grid using the default settings. In either case, if you resize columns or move columns, and then close the project, the next time you load things, it should display the grid as you left it. Currently, there is not a columnwidth property as a member of GridBoundColumn. To set the widths, you use this.gridDataBoundGrid1.Model.ColWidths[2] = 100; //set width of col 2 to 100


UN Unknown Syncfusion Team April 17, 2003 04:36 PM UTC

Many thanks for the project - your project works fine. However, when I tried to convert it to VB I couldn't get it to work: Public Sub ReadLayout(ByVal grid As GridDataBoundGrid) Dim fileName As String = grid.FindForm.Name & "." & grid.Name & ".bin" If IO.File.Exists(fileName) Then Try Dim formatter As IFormatter = New Binary.BinaryFormatter Dim stream As IO.Stream = New FileStream(fileName, FileMode.Open, FileAccess.Read, FileShare.None) Try grid.BeginUpdate() Dim col As GridBoundColumnsCollection = CType(grid.GridBoundColumns.Clone, GridBoundColumnsCollection) If col.Count = 0 Then col = grid.Binder.InternalColumns End If Dim a As String() = CType(formatter.Deserialize(stream), String()) grid.GridBoundColumns.Clear() For Each s As String In a grid.GridBoundColumns.Add(col(s)) Next grid.Model.ColWidths.Dictionary = CType(formatter.Deserialize(stream), Syncfusion.Windows.Forms.Grid.GridRowColSizeDictionary) Catch ex As Exception MessageBox.Show(ex.ToString) Finally grid.EndUpdate() grid.Refresh() stream.Close() End Try Catch ex As Exception MessageBox.Show(ex.ToString) End Try Else Me.WriteLayout(grid) End If End Sub Public Sub WriteLayout(ByVal grid As GridDataBoundGrid) Try Dim fileName As String = grid.FindForm.Name & "." & grid.Name & ".bin" Dim formatter As IFormatter = New Binary.BinaryFormatter Dim stream As Stream = New FileStream(fileName, FileMode.Create, FileAccess.Write, FileShare.None) Dim col As GridBoundColumnsCollection = grid.GridBoundColumns If col.Count = 0 Then col = grid.Binder.InternalColumns End If Dim a(col.Count - 1) As String Dim i As Integer = 0 For Each c As GridBoundColumn In col a(i) = c.MappingName i += 1 Next formatter.Serialize(stream, a) formatter.Serialize(stream, grid.Model.ColWidths.Dictionary) stream.Close() Catch ex As Exception MessageBox.Show(ex.ToString) End Try End Sub Thanks Jeremy P.S. I just ordered the suite - where will I be able to get the 1.6 version from?


AD Administrator Syncfusion Team April 17, 2003 07:25 PM UTC

Attached is both VB & C# projects. There seems to be a problem with this code For Each s As String In a It does not interate through the same values as in C#. The attached project just uses an integer to iterate through the array. 1.6 will be in beta this week. Users will receive notification when it is released. You can check for the latest releases from your support home page on our web site.


UN Unknown Syncfusion Team April 18, 2003 12:35 PM UTC

Clay Thanks very much for your help Regards Jeremy

Loader.
Live Chat Icon For mobile
Up arrow icon