| 'this method should be called on Pre_Render of grid |
| Public Function ReadSettings() As String |
| Try |
| Dim gridSettings() As Object = New Object((6) - 1) {} |
| 'Save sort expressions |
| gridSettings(0) = CType(gridInstance.MasterTableView.SortExpressions, IStateManager).SaveViewState |
| |
| 'Save groupBy |
| Dim groupByExpressions As GridGroupByExpressionCollection = gridInstance.MasterTableView.GroupByExpressions |
| Dim groupExpressions() As Object = New Object((groupByExpressions.Count) - 1) {} |
| Dim count As Integer = 0 |
| For Each expression As GridGroupByExpression In groupByExpressions |
| groupExpressions(count) = CType(expression, IStateManager).SaveViewState |
| count = (count + 1) |
| Next |
| gridSettings(1) = groupExpressions |
| |
| 'Save visible columns |
| Dim columnsLength As Integer = (gridInstance.MasterTableView.Columns.Count + gridInstance.MasterTableView.AutoGeneratedColumns.Length) |
| Dim columnOrder() As Pair = New Pair(columnsLength - 1) {} |
| Dim allColumns As ArrayList = New ArrayList(columnsLength) |
| Dim visibleColumns As ArrayList = New ArrayList(columnsLength) |
| |
| allColumns.AddRange(gridInstance.MasterTableView.Columns) |
| allColumns.AddRange(gridInstance.MasterTableView.AutoGeneratedColumns) |
| Dim i As Integer = 0 |
| For Each column As GridColumn In allColumns |
| Dim p As Pair = New Pair |
| p.First = column.OrderIndex |
| p.Second = column.HeaderStyle.Width |
| columnOrder(i) = p |
| visibleColumns.Add(column.Visible) |
| i = (i + 1) |
| Next |
| gridSettings(2) = columnOrder |
| gridSettings(3) = visibleColumns |
| |
| 'Save PageSize |
| gridSettings(4) = CType(gridInstance.PageSize, Object) |
| 'Save detail grid sort expressions |
| Dim nextindextosave As Integer = 5 |
| 'If you have several detail tables at a level then you can get the count of the detailtables in the grid using the following code: |
| |
| If gridInstance.MasterTableView.DetailTables.Count > 0 Then |
| Dim j As Integer |
| For j = 0 To gridInstance.MasterTableView.DetailTables.Count - 1 |
| 'If you want to check the count of the detailtables at each level of the grid, then you would have to try the following code: |
| If gridInstance.MasterTableView.DetailTables(j).DetailTables.Count > 0 Then |
| ReDim gridSettings(gridSettings.Length + gridInstance.MasterTableView.DetailTables(j).DetailTables.Count) |
| Else |
| gridSettings(5) = CType(gridInstance.MasterTableView.DetailTables(j).SortExpressions, IStateManager).SaveViewState |
| |
| End If |
| Next |
| End If |
| Dim formatter As LosFormatter = New LosFormatter |
| Dim writer As StringWriter = New StringWriter |
| formatter.Serialize(writer, gridSettings) |
| Return writer.ToString |
| Catch ex As Exception |
| Throw ex |
| End Try |
| End Function |
| |
| |
| 'this method should be called on PageInit |
| Public Function LoadSettings(ByVal settings As String) |
| Try |
| If ((settings = "") Or (settings Is DBNull.Value)) Then |
| Return False |
| End If |
| Dim formatter As LosFormatter = New LosFormatter() |
| Dim reader As StringReader = New StringReader(settings) |
| Dim gridSettings() As Object = CType(formatter.Deserialize(reader), Object()) |
| |
| 'Load sort expressions |
| Me.gridInstance.MasterTableView.SortExpressions.Clear() |
| CType(Me.gridInstance.MasterTableView.SortExpressions, IStateManager).LoadViewState(gridSettings(0)) |
| 'Load groupBy |
| Dim groupByExpressions As GridGroupByExpressionCollection = Me.gridInstance.MasterTableView.GroupByExpressions |
| groupByExpressions.Clear() |
| Dim groupExpressionsState As Object() = CType(gridSettings(1), Object()) |
| Dim count As Integer = 0 |
| For Each obj As Object In groupExpressionsState |
| Dim expression As GridGroupByExpression = New GridGroupByExpression() |
| CType(expression, IStateManager).LoadViewState(obj) |
| groupByExpressions.Add(expression) |
| countcount = count + 1 |
| Next |
| |
| 'load visible columns |
| Dim columnsLength As Integer = (Me.gridInstance.MasterTableView.Columns.Count + Me.gridInstance.MasterTableView.AutoGeneratedColumns.Length) |
| Dim columnOrder() As Pair = CType(gridSettings(2), Pair()) |
| Dim visibleCols As ArrayList = CType(gridSettings(3), ArrayList) |
| |
| If columnsLength = columnOrder.Length Then |
| Dim allColumns As ArrayList = New ArrayList(columnsLength) |
| allColumns.AddRange(Me.gridInstance.MasterTableView.Columns) |
| allColumns.AddRange(Me.gridInstance.MasterTableView.AutoGeneratedColumns) |
| |
| Dim i As Integer = 0 |
| For Each column As GridColumn In allColumns |
| column.OrderIndex = CType(columnOrder(i).First, Integer) |
| column.HeaderStyle.Width = CType(columnOrder(i).Second, Unit) |
| column.Visible = CType(visibleCols(i), Boolean) |
| ii = i + 1 |
| Next |
| End If |
| 'Load page size |
| Me.gridInstance.PageSize = CType(gridSettings(4), Integer) |
| |
| If gridInstance.MasterTableView.DetailTables.Count > 0 Then |
| Dim j As Integer |
| For j = 0 To gridInstance.MasterTableView.DetailTables.Count - 1 |
| 'If you want to check the count of the detailtables at each level of the grid, then you would have to try the following code: |
| If gridInstance.MasterTableView.DetailTables(j).DetailTables.Count > 0 Then |
| Me.gridInstance.MasterTableView.DetailTables(j).SortExpressions.Clear() |
| CType(Me.gridInstance.MasterTableView.DetailTables(j).SortExpressions, IStateManager).LoadViewState(gridSettings(5)) |
| ReDim gridSettings(gridSettings.Length + gridInstance.MasterTableView.DetailTables(j).DetailTables.Count) |
| Else |
| Me.gridInstance.MasterTableView.DetailTables(j).SortExpressions.Clear() |
| CType(Me.gridInstance.MasterTableView.DetailTables(j).SortExpressions, IStateManager).LoadViewState(gridSettings(5)) |
| |
| End If |
| Next |
| End If |
| Catch ex As Exception |
| Throw ex |
| End Try |
| End Function |