Declined
Last Updated: 31 Mar 2014 10:12 by ADMIN
ADMIN
Dess | Tech Support Engineer, Principal
Created on: 05 Dec 2013 08:57
Category: GridView
Type: Bug Report
2
FIX. RadGridView - DataException loading layout
To reproduce:
- add RadGridView and fill it with data;
- use the following code for saving the layout: string layout;
using (MemoryStream ms = new MemoryStream())
{
    radGridView1.SaveLayout(ms);
    ms.Position = 0;
    byte[] buffer = new byte[ms.Length - 1];

    ms.Read(buffer, 0, buffer.Length);
    layout = Convert.ToBase64String(buffer);
    ms.Close();
}

When you try to load the saved layout, using the following code, DataException is thrown:
using (MemoryStream stream = new MemoryStream(Convert.FromBase64String(layout)))
{
    radGridView1.LoadLayout(stream);
}

Workaround: save the layout in xml file
1 comment
ADMIN
Ralitsa
Posted on: 20 Mar 2014 08:45
Resolution: 
The described case is not an issue. The undesired behavior appears due incorrect creating and filling of the byte array. In the provided source code the byte array has smaller length that memory stream which leads to the issue.

Correct code: 
 using (MemoryStream ms = new MemoryStream())
 {
     radGridView1.SaveLayout(ms);
     ms.Position = 0;
     byte[] buffer = new byte[ms.Length];  //this line was byte[] buffer = new byte[ms.Length - 1];
     ms.Read(buffer, 0, buffer.Length);
     layout = Convert.ToBase64String(buffer);
 }