however it is giving me compile errors when i try to view it. In Visual Studioacts like it builds but flags an erro on the User Control calling this class.
The Error Reported is
Compilation
Error
Description: An error occurred during the compilation of a resource required to service this request. Please review the following specific error details and modify your source code appropriately.
Compiler
Error
Message: BC30201: Expression expected.
Source
Error
:
Line 258:
Line 259:
Private
Sub
Grid_ColumnCreated(
ByVal
sender
As
Object
,
ByVal
e
As
GridColumnCreatedEventArgs)
Line 260:
Dim
colSettings
As
ColumnSettings = Settings.AutoGeneratedColumnSettings.Find(
Function
(cs) cs.UniqueName = e.Column.UniqueName)
Line 261:
Dim
column
As
GridColumn = e.Column
Line 262:
Source File: C:\Documents and Settings\ddownie\My Documents\SasquatchV11\App_Code\GridSettingsPersister.vb Line: 260
Private Sub Grid_ColumnCreated(ByVal sender As Object, ByVal e As GridColumnCreatedEventArgs)
Dim colSettings As ColumnSettings = Settings.AutoGeneratedColumnSettings.Find(Function(cs) cs.UniqueName = e.Column.UniqueName)
Dim column As GridColumn = e.Column
If colSettings IsNot Nothing Then
SetColumnSettings(column, colSettings)
End If
End Sub
can anyone see what i might have to change or is there an update for this call file ?
12 Answers, 1 is accepted
Please, try replacing the code in the method with this code and let us know if it fixes the issue:
Private
Sub
Grid_ColumnCreated(sender
As
Object
, e
As
GridColumnCreatedEventArgs)
Dim
settings
As
ColumnSettings = Settings.AutoGeneratedColumnSettings.Find(
Function
([set]
As
ColumnSettings)
Do
Return
[set].UniqueName = e.Column.UniqueName
End
Function
)
Dim
column
As
GridColumn = e.Column
If
settings <>
Nothing
Then
SetColumnSettings(column, settings)
End
If
End
Sub
All the best,
Tsvetina
the Telerik team

http://demos.telerik.com/aspnet-ajax/grid/examples/programming/savinggridsettingsonperuserbasis/defaultvb.aspx
Here are the compile errors the new code tosses.
Error 1 Expression expected. C:\Documents and Settings\ddownie\My Documents\SasquatchV11\App_Code\GridSettingsPersister.vb 270 112 C:\...\SasquatchV11\
Error 2 'Return' statement in a Sub or a Set cannot return a value. C:\Documents and Settings\ddownie\My Documents\SasquatchV11\App_Code\GridSettingsPersister.vb 271 9 C:\...\SasquatchV11\
Error 3 'End Sub' expected. C:\Documents and Settings\ddownie\My Documents\SasquatchV11\App_Code\GridSettingsPersister.vb 272 3 C:\...\SasquatchV11\
Error 4 End of statement expected. C:\Documents and Settings\ddownie\My Documents\SasquatchV11\App_Code\GridSettingsPersister.vb 272 15 C:\...\SasquatchV11\
Error 5 Name 'e' is not declared. C:\Documents and Settings\ddownie\My Documents\SasquatchV11\App_Code\GridSettingsPersister.vb 273 32 C:\...\SasquatchV11\
Error 6 Statement cannot appear outside of a method body. C:\Documents and Settings\ddownie\My Documents\SasquatchV11\App_Code\GridSettingsPersister.vb 274 3 C:\...\SasquatchV11\
Error 7 Declaration expected. C:\Documents and Settings\ddownie\My Documents\SasquatchV11\App_Code\GridSettingsPersister.vb 275 4 C:\...\SasquatchV11\
Error 8 'End If' must be preceded by a matching 'If'. C:\Documents and Settings\ddownie\My Documents\SasquatchV11\App_Code\GridSettingsPersister.vb 276 3 C:\...\SasquatchV11\
Error 9 'End Sub' must be preceded by a matching 'Sub'. C:\Documents and Settings\ddownie\My Documents\SasquatchV11\App_Code\GridSettingsPersister.vb 277 2 C:\...\SasquatchV11\

This one does not cause any errors, but it does not re-load any settings either. It does seem to make a serialized string when i save it - however i just noticed that the string is always the same - no matter what sorting or filtering i have done.
/wEUKwAIZGRkZRYRZ2dnZ2dnZ2dnZ2dnZ2dnZ2cWEWdnZ2dnZ2dnZ2dnZ2dnZ2dnFCoSU3lzdGVtLldlYi5VSS5QYWlyEg8LKXpUZWxlcmlrLldlYi5VSS5HcmlkS25vd25GdW5jdGlvbiwgVGVsZXJpay5XZWIuVUksIFZlcnNpb249MjAwOS4zLjEzMTQuMjAsIEN1bHR1cmU9bmV1dHJhbCwgUHVibGljS2V5VG9rZW49MTIxZmFlNzgxNjViYTNkNABlDwsrBQBlDwsrBQBlDwsrBQBlDwsrBQBlDwsrBQBlDwsrBQBlDwsrBQBlDwsrBQBlDwsrBQBlDwsrBQBlDwsrBQBlDwsrBQBlDwsrBQBlDwsrBQBlDwsrBQBlDwsrBQBlZGQ=
Here is the alternate script i found.
Imports Microsoft.VisualBasic
Imports Telerik.Web.UI
Imports System.IO
Public Class GridSettings
Private gridInstance As RadGrid
Public Sub New(ByVal gridInstance As RadGrid)
Me.gridInstance = gridInstance
End Sub
'this method should be called on Render
Public Function SaveSettings() As String
Dim gridSettings As Object() = New Object(7) {}
Dim columnsLength As Integer = gridInstance.MasterTableView.Columns.Count + gridInstance.MasterTableView.AutoGeneratedColumns.Length
Dim allColumns As New ArrayList(columnsLength)
allColumns.AddRange(gridInstance.MasterTableView.Columns)
allColumns.AddRange(gridInstance.MasterTableView.AutoGeneratedColumns)
'***************** Save filters ******************
gridSettings(3) = DirectCast(gridInstance.MasterTableView.FilterExpression, Object)
'save the visible/displayed columns settings and current filter value/current filter function
Dim visibleColumns As New ArrayList(columnsLength)
Dim displayedColumns As New ArrayList(columnsLength)
Dim columnFilter As Pair() = New Pair(columnsLength) {}
Dim i As Integer = 0
For Each column As GridColumn In allColumns
columnFilter(i) = New Pair(column.CurrentFilterFunction, column.CurrentFilterValue)
visibleColumns.Add(column.Visible)
displayedColumns.Add(column.Display)
System.Math.Max(System.Threading.Interlocked.Increment(i), i - 1)
Next
gridSettings(4) = visibleColumns
gridSettings(5) = displayedColumns
gridSettings(6) = columnFilter
'***************************************************
Dim formatter As New LosFormatter()
Dim writer As New StringWriter()
formatter.Serialize(writer, gridSettings)
Return writer.ToString()
End Function
'this method should be called on PageInit
Public Sub LoadSettings(ByVal settings As String)
Dim formatter As New LosFormatter()
Dim reader As New StringReader(settings)
Dim gridSettings As Object() = DirectCast(formatter.Deserialize(reader), Object())
Dim columnsLength As Integer = Me.gridInstance.MasterTableView.Columns.Count + Me.gridInstance.MasterTableView.AutoGeneratedColumns.Length
Dim allColumns As New ArrayList(columnsLength)
allColumns.AddRange(Me.gridInstance.MasterTableView.Columns)
allColumns.AddRange(Me.gridInstance.MasterTableView.AutoGeneratedColumns)
'***************** Load filter expression ******************
Me.gridInstance.MasterTableView.FilterExpression = DirectCast(gridSettings(3), String)
'Load visible/displayed columns and their current filter values/current filter functions
Dim visibleCols As ArrayList = DirectCast(gridSettings(4), ArrayList)
Dim displayedColumns As ArrayList = DirectCast(gridSettings(5), ArrayList)
Dim columnFilter As Pair() = DirectCast(gridSettings(6), Pair())
Dim j As Integer = 0
For Each column As GridColumn In allColumns
column.CurrentFilterFunction = DirectCast(columnFilter(j).First, GridKnownFunction)
column.CurrentFilterValue = DirectCast(columnFilter(j).Second, String)
column.Visible = DirectCast(visibleCols(j), Boolean)
column.Display = DirectCast(displayedColumns(j), Boolean)
System.Math.Max(System.Threading.Interlocked.Increment(j), j - 1)
Next
'*************************************************************
End Sub
End Class
'=======================================================
'Service provided by Telerik (www.telerik.com)
'Conversion powered by NRefactory.
'Built and maintained by Todd Anglin and Telerik
'=======================================================
I prepared a sample project for you to test locally. It uses the code from the online demo and works without problems on my side. Please, try to replicate the problem that you encounter in it and let me know what changes were made in order to do so.
Additionally, a possible reason could be the version of .NET framework that you are building your project against. If it is 2.0 have you also tried running this code under .NET 3.5?
Regards,
Tsvetina
the Telerik team

I did run your sample in 3.5 with your web.config
That may solve my compilation problem most likely.
However ... i am still not seeing anything happen when I click the Load Settings Button.
I filtered for Accounts containing A Then Saved those settings with User1
I cleared the filters, Selected B for my filter and saved for User 2
Then did the same for User3 with C Customers.
I then switch to user1 and click load settings - nothing happens - the grid should come back with all customers containing A right ?
it doesn't
Is that the behavior i should expect ? Is that what happens when you run it ?

When examining session strings, all 3 look exactly the same

On your demo
http://demos.telerik.com/aspnet-ajax/grid/examples/programming/savinggridsettingsonperuserbasis/defaultcs.aspx
I can get it to run fine in C# But it does not work in VB
It is still behaving just like this project you sent - it does nothing when you try to reload settings !
Stuff in that class is beyond what i know so i do appreciate the help you have given.
But try that demo in VB please.
I had our QA guy try it on his PC and he experienced the same as me.
Works in C# not in VB

To finally make the magic happen I had to add 1 line
RadGrid1.Rebind()
The simplest things take the longest to figure out.
Protected
Sub
Button2_Click(
ByVal
sender
As
Object
,
ByVal
e
As
EventArgs)
Dim
combo
As
RadComboBox =
CType
(Page.FindControl(
"UserSelection"
), RadComboBox)
Dim
user
As
String
=
CType
(combo.SelectedValue,
String
)
Dim
LoadPersister
As
New
GridSettingsPersister(RadGrid1)
If
Session(user) =
Nothing
Then
StatusLabel.Text =
"No saved settings for this user were found!"
Else
Dim
settings
As
String
=
DirectCast
(Session(user),
String
)
LoadPersister.LoadSettings(settings)
RadGrid1.Rebind()
StatusLabel.Text =
"Settings for "
+ user +
" were restored successfully!"
End
If
End
Sub
Indeed, the call to Rebind() is skipped in the VB version. Thank you for pointing this out. We will fix it, so we avoid further confusion.
Kind regards,
Tsvetina
the Telerik team

Hi,
I am having the same problem but where I work they only use Framework v2.0
How can I adapt the code below ?
Regards
Private Sub Grid_ColumnCreated(ByVal sender As Object, ByVal e As GridColumnCreatedEventArgs)
Dim colSettings As ColumnSettings = Settings.AutoGeneratedColumnSettings.Find(Function(cs) cs.UniqueName = e.Column.UniqueName )
Dim column As GridColumn = e.Column
If colSettings IsNot Nothing Then
SetColumnSettings(column, colSettings)
End If
End Sub

Private Sub Grid_ColumnCreated(ByVal sender As Object, ByVal e As GridColumnCreatedEventArgs)
'Dim colSettings As ColumnSettings = Settings.AutoGeneratedColumnSettings.Find(Function(cs) cs.UniqueName = e.Column.UniqueName)
Dim colSettings As ColumnSettings
For Each oCol In Settings.AutoGeneratedColumnSettings
If oCol.UniqueName = e.Column.UniqueName Then
colSettings = oCol
Exit For
End If
Next oCol
Dim column As GridColumn = e.Column
If colSettings IsNot Nothing Then
SetColumnSettings(column, colSettings)
End If
End Sub

Here is what I changed and it is working in 2.0 !!!! (except for column width)
Private Sub Grid_ColumnCreated(ByVal sender As Object, ByVal e As GridColumnCreatedEventArgs)
Dim colSettings As ColumnSettings = Nothing
For Each colSettings In Settings.AutoGeneratedColumnSettings
If colSettings.UniqueName = e.Column.UniqueName Then
colSettings = colSettings
Exit For
End If
Next colSettings
Dim column As GridColumn = e.Column
If colSettings IsNot Nothing Then
SetColumnSettings(column, colSettings)
End If
End Sub