This is a migrated thread and some comments may be shown as answers.

GridSettingsPersister

12 Answers 150 Views
Grid
This is a migrated thread and some comments may be shown as answers.
David
Top achievements
Rank 1
David asked on 23 Dec 2010, 09:15 PM
I have copied the VB code from the sample on Persisting the Grid state in a session.

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

on this fuction:
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

Sort by
0
Tsvetina
Telerik team
answered on 28 Dec 2010, 08:30 AM
Hello David,

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
Browse the vast support resources we have to jump start your development with RadControls for ASP.NET AJAX. See how to integrate our AJAX controls seamlessly in SharePoint 2007/2010 visiting our common SharePoint portal.
0
David
Top achievements
Rank 1
answered on 29 Dec 2010, 07:20 PM
That seemed to have made it worse - it won't compile with that Sub now.  And for what it is worth - i can not even get the Demo to save user Settings at all.
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\
0
David
Top achievements
Rank 1
answered on 29 Dec 2010, 07:29 PM
I found a different version of this class to save an load settings.  i used your translator to turn it into VB

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
'=======================================================
0
Tsvetina
Telerik team
answered on 04 Jan 2011, 10:00 AM
Hello David,

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
Browse the vast support resources we have to jump start your development with RadControls for ASP.NET AJAX. See how to integrate our AJAX controls seamlessly in SharePoint 2007/2010 visiting our common SharePoint portal.
0
David
Top achievements
Rank 1
answered on 04 Jan 2011, 04:29 PM
My original project is in 2.0
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 ?

0
David
Top achievements
Rank 1
answered on 04 Jan 2011, 05:24 PM


When examining session strings,  all 3 look exactly the same
0
David
Top achievements
Rank 1
answered on 04 Jan 2011, 06:27 PM
I just realized something !!!

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

0
David
Top achievements
Rank 1
answered on 04 Jan 2011, 08:19 PM
One more note from me. After fidling with this and shcnging multiple things each time - I could see the values loading appropriately when debugging.

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
0
Tsvetina
Telerik team
answered on 07 Jan 2011, 11:41 AM
Hi David,

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
Browse the vast support resources we have to jump start your development with RadControls for ASP.NET AJAX. See how to integrate our AJAX controls seamlessly in SharePoint 2007/2010 visiting our common SharePoint portal.
0
Florent
Top achievements
Rank 1
answered on 31 Jan 2011, 11:39 AM

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

0
Florent
Top achievements
Rank 1
answered on 02 Feb 2011, 09:29 AM
Here below the solution that I find and it's working perfectly

 

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

 

0
David
Top achievements
Rank 1
answered on 02 Feb 2011, 06:47 PM
In that code - oCol  is not declared, and causes compile errors.

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




Tags
Grid
Asked by
David
Top achievements
Rank 1
Answers by
Tsvetina
Telerik team
David
Top achievements
Rank 1
Florent
Top achievements
Rank 1
Share this question
or