Save Colors in Layout

4 posts, 1 answers
  1. ahmad
    ahmad avatar
    2 posts
    Member since:
    Jan 2016

    Posted 10 Jan Link to this post

    I save RadGridView layout in SQL using the following code:

    string name = Microsoft.VisualBasic.Interaction.InputBox("Please insert the layout name:", " ");
    using (MemoryStream ms = new MemoryStream())
    {
        var lay = new Rahat.Layout();
        lay.User_Id = 123;
        lay.Title = name;
        #region lay.Layout
        grid.SaveLayout(ms);
        var sw = new StreamWriter(ms);
        sw.Flush();
        ms.Position = 0;
        var sr = new StreamReader(ms);
        var myStr = sr.ReadToEnd();
        lay.Layout = myStr;
        #endregion
        _dbRahat.Layouts.InsertOnSubmit(lay);
        _dbRahat.SubmitChanges();
    }

    and load the layout using the following code:

    var lay = _dbRahat.Layouts.First(l => l.Id.ToString() == cmbPreset.SelectedValue.ToString());
     
    byte[] byteArray = Encoding.UTF8.GetBytes(lay.Layout);
    var stream = new MemoryStream(byteArray);
    grid.LoadLayout(stream);
     
    FillGrid();

    The problem is that the grid colors (header cell colors, data cell colors) are not saved and loaded with SaveLayout() and LoadLayout() methods. How can I solve this problem?

    Thank you

  2. Answer
    Dimitar
    Admin
    Dimitar avatar
    1415 posts

    Posted 13 Jan Link to this post

    Hello Ahmad,

    Thank you for writing.

    The Save/Load functionality only saves logical layout information (like columns position and size). It does not save any styling properties. In this case, you can save the colors as application settings: c# - Save Settings in a .NET Winforms Application - Stack Overflow

    I hope this helps.

    Regards,
    Dimitar
    Telerik
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
  3. UI for WinForms is Visual Studio 2017 Ready
  4. ahmad
    ahmad avatar
    2 posts
    Member since:
    Jan 2016

    Posted 13 Jan in reply to Dimitar Link to this post

    If I change cell colors and then load layout then colors are disappeared? How can I prevent from this?
  5. Dimitar
    Admin
    Dimitar avatar
    1415 posts

    Posted 18 Jan Link to this post

    Hi Ahmad,

    Thank you for writing.

    Please note that all rows and columns are recreated when the layout is loaded and if you are using the Style property to change the grid appearance the styles will be reset. In this case, you should either set the styles after the layout is loaded or use the formatting events to style the grid.

    I hope this will be useful. 

    Regards,
    Dimitar
    Telerik
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
Back to Top