Completed
Last Updated: 11 Dec 2015 14:05 by ADMIN
ADMIN
Dess | Tech Support Engineer, Principal
Created on: 23 Apr 2014 13:56
Category: GridView
Type: Bug Report
1
FIX. RadGridView - Copy functionality drops the opening/closing TABLE/TR tags when the first/last column is hidden
To reproduce:
Add a RadGridView and fill it with data. Set the first column's IsVisible property to false. Right click over the row to Copy the row content and paste it in Excel. All data is in a single cell. The Clipboard content does not contain the corresponding <TABLE><TR> tags.

Note: if the last columns is hidden, the line-breaks in the copied text are missing.

Workaround: create custom RadGridView and replace the wrong content in the Clipboard:
public class CustomGrid : RadGridView
{
    protected override RadGridViewElement CreateGridViewElement()
    {
        return new CustomRadGridViewElement();
    }
}

public class CustomRadGridViewElement : RadGridViewElement
{
    protected override MasterGridViewTemplate CreateTemplate()
    {
        return new CustomMasterGridViewTemplate();
    }
}

public class CustomMasterGridViewTemplate : MasterGridViewTemplate
{
    public override void Copy()
    {
        base.Copy();
        
        if (Clipboard.ContainsData(DataFormats.Html))
        {
            string data = Clipboard.GetData(DataFormats.Html).ToString();
            StringBuilder sb = new StringBuilder(data);
            if (!data.Contains("<TABLE>"))
            {
                int insertIndex = data.IndexOf("<TD>");
                sb.Insert(insertIndex, "<TABLE><TR>");
            }
            else if (!data.Contains("</TABLE>"))
            {
                int insertIndex = data.LastIndexOf("<TD>");
                sb.Insert(insertIndex, "</TR></TABLE>");
            }
            
            Clipboard.SetData(DataFormats.Html, sb.ToString());
        }
    }
}
0 comments