RadDock Example from vb to c# !!

3 posts, 1 answers
  1. A.mass
    A.mass avatar
    30 posts
    Member since:
    Apr 2009

    Posted 26 Apr 2009 Link to this post

    Hello everyone,
    I found an interesting easy working example for RadDock but teh problem that I'm facing that its in vb, and the application is c#
    can anyone help me to convert it [ Please note that the online converters couldn't convert it specially the bold + underlined lines ]

    Imports System 
    Imports System.Data 
    Imports System.Configuration 
    Imports System.Collections 
    Imports System.Web 
    Imports System.Web.Security 
    Imports System.Web.UI 
    Imports System.Web.UI.WebControls 
    Imports System.Web.UI.WebControls.WebParts 
    Imports System.Web.UI.HtmlControls 
    Imports System.Data.SqlClient 
    Imports Telerik.Web.UI 
    Imports System.Collections.Generic 
    Imports System.Text 
    Imports System.Web.Script.Serialization 
    Partial Public Class DefaultVB 
        Inherits System.Web.UI.Page 
        Private _conn As New SqlConnection(ConfigurationManager.ConnectionStrings("DockConnectionString").ConnectionString) 
        Private _count As Integer = 0 
        Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs) 
        End Sub 
        Protected Sub RadDockLayout1_LoadDockLayout(ByVal sender As Object, ByVal e As Telerik.Web.UI.DockLayoutEventArgs) 
            Dim dock As RadDock = Nothing 
            Dim serializer As New JavaScriptSerializer() 
            Dim converters As New List(Of JavaScriptConverter)() 
            converters.Add(New UnitConverter()) 
            'Get saved state string from the database - set it to dockState variable for example  
            Dim dockState As String = "" 
                Dim command As New SqlCommand("select State from States where id=1", _conn) 
                dockState = command.ExecuteScalar().ToString() 
            End Try 
            Dim currentDockStates As String() = dockState.Split("|"c) 
            For Each stringState As String In currentDockStates 
                If stringState.Trim() <> String.Empty Then 
                    Dim state As DockState = serializer.Deserialize(Of DockState)(stringState) 
                    e.Positions(state.UniqueName) = state.DockZoneID 
                    e.Indices(state.UniqueName) = state.Index 
                    dock = DirectCast(RadDockLayout1.FindControl(state.UniqueName), RadDock) 
                End If 
        End Sub 
        Protected Sub RadDockLayout1_SaveDockLayout(ByVal sender As Object, ByVal e As Telerik.Web.UI.DockLayoutEventArgs) 
            Dim dockState As String 
            Dim serializer As New JavaScriptSerializer() 
            Dim converters As New List(Of JavaScriptConverter)() 
            converters.Add(New UnitConverter()) 
            Dim stateList As List(Of DockState) = RadDockLayout1.GetRegisteredDocksState() 
            Dim serializedList As New StringBuilder() 
            Dim i As Integer = 0 
            While i < stateList.Count 
                System.Math.Max(System.Threading.Interlocked.Increment(i), i - 1) 
            End While 
            dockState = serializedList.ToString() 
            If dockState.Trim() <> [String].Empty Then 
                    Dim command As New SqlCommand([String].Format("update States set State='{0}' where id=1", dockState), _conn) 
                End Try 
            End If 
        End Sub 
    End Class 

    Thank you in advance
  2. Answer
    ManniAT avatar
    885 posts
    Member since:
    Nov 2003

    Posted 27 Apr 2009 Link to this post

    Telrik offers a nice code converter - try it here with your code:

    By the way - the first underlined line seems to be an error for me - UnitConverter is not a kind of JavaScriptConverter.
    For the second line you have to change the result:
    System.Math.Max(System.Threading.Interlocked.Increment(i), i - 1);  
    System.Math.Max(System.Threading.Interlocked.Increment(ref i), i - 1); 


  3. Tom
    Tom avatar
    8 posts
    Member since:
    Oct 2009

    Posted 14 Dec 2009 Link to this post

    I don't know if you found the missing UnitConverter or not, but Google sent me here so I thought I would update it.  The UnitConverter in the example (http://www.telerik.com/community/forums/aspnet-ajax/docking/is-it-possible-to-save-and-load-a-dock-s-collapse-state.aspx) has a UnitConverter class in the App_Code folder.  You have to create that class yourself in your solution.

    Here is my converted C# version:

    using System;  
    using System.Data;  
    using System.Configuration;  
    using System.Web;  
    using System.Web.Security;  
    using System.Web.UI;  
    using System.Web.UI.WebControls;  
    using System.Web.UI.WebControls.WebParts;  
    using System.Web.UI.HtmlControls;  
    using System.Web.Script.Serialization;  
    using System.Collections.ObjectModel;  
    using System.Collections.Generic;  
    namespace YourNameSpace  
        public class UnitConverter : JavaScriptConverter  
            public override object Deserialize(System.Collections.Generic.IDictionary<string, object> dictionary, Type type, JavaScriptSerializer serializer)  
                if (dictionary == null)  
                    throw new ArgumentNullException("dictionary");  
                if (object.ReferenceEquals(type, typeof(Unit)))  
                    double value = Convert.ToDouble(dictionary["Value"]);  
                    UnitType unitType = (UnitType)Enum.Parse(typeof(UnitType), dictionary["Type"].ToString());  
                    Unit unit = new Unit(value, unitType);  
                    return unit;  
                return null;  
            public override System.Collections.Generic.IDictionary<string, object> Serialize(object obj, JavaScriptSerializer serializer)  
                Unit unit = (Unit)obj;  
                if (unit != null)  
                    Dictionary<string, object> dict = new Dictionary<string, object>();  
                    dict.Add("Type", unit.Type);  
                    dict.Add("Value", unit.Value);  
                    return dict;  
                return new Dictionary<string, object>();  
            public override System.Collections.Generic.IEnumerable<Type> SupportedTypes  
                get { return new ReadOnlyCollection<Type>(new List<Type>(new Type[] { typeof(Unit) })); }  

Back to Top