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.
Unfortunately, activation email could not send to your email. Please try again.

Saving grid properties for a GridDatabound

Thread ID:

Created:

Updated:

Platform:

Replies:

3918 Apr 17,2003 10:10 AM Apr 18,2003 08:35 AM Windows Forms 4
loading
Tags: GridControl
Jeremy Holt
Asked On April 17, 2003 10:10 AM

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

Administrator [Syncfusion]
Replied On April 17, 2003 10:59 AM

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

Jeremy Holt
Replied On April 17, 2003 12:36 PM

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?

Administrator [Syncfusion]
Replied On April 17, 2003 03:25 PM

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.

Jeremy Holt
Replied On April 18, 2003 08:35 AM

Clay Thanks very much for your help Regards Jeremy

CONFIRMATION

This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.

;