Completed
Last Updated: 31 Mar 2014 09:21 by ADMIN
ADMIN
Dess | Tech Support Engineer, Principal
Created on: 13 Nov 2013 09:24
Category: GridView
Type: Bug Report
2
FIX. RadGridView - the built in copy function is not working for child template
To reproduce: 
- add RadGridView and populate it manually with hierarchical data; 
- open one row child rows and select several child rows; 
- right click to open the context menu and select Copy; 
- paste in Notepad for example. As a result there is no pasted data. 

Workaround: 
radGridView1.ContextMenuOpening += radGridView1_ContextMenuOpening; 
string clipBoard = string.Empty;
RadGridView contextMenuInvoker;

void radGridView1_ContextMenuOpening(object sender, Telerik.WinControls.UI.ContextMenuOpeningEventArgs e) 
        {
            RadGridView grid = sender as RadGridView;
            if (grid.CurrentCell is GridDataCellElement || grid.CurrentCell is GridTableBodyElement)
            {
                if (grid.CurrentRow.ViewTemplate != grid.MasterGridViewTemplate && !(grid.CurrentCell.RowInfo is GridViewNewRowInfo))
                {
                    RadMenuItem itemCopy = new RadMenuItem();
                    itemCopy.Text = "Copy Row(s)";
                    itemCopy.Click += new EventHandler(itemCopy_Click);
                    e.ContextMenu.Items.RemoveAt(3);
                    e.ContextMenu.Items.Insert(3, itemCopy);
                    e.ContextMenu.Items.RemoveAt(4);
                }
                contextMenuInvoker = grid;
            }
        }

        void itemCopy_Click(object sender, EventArgs e)
        {
            CopyRows(contextMenuInvoker);
        }

        private void CopyRows(RadGridView radGridView)
        {
            StringBuilder sb = new StringBuilder();
            foreach (GridViewRowInfo row in radGridView.SelectedRows)
            {
                int i = 0;
                while (i < row.Cells.Count)
                {
                    if (i > 0)
                    {
                        sb.Append(",");
                    }
                    sb.Append(row.Cells[i].Value.ToString());
                    i++;
                }
                sb.AppendLine(";");
            }
            clipBoard = sb.ToString();
            Clipboard.SetDataObject(clipBoard);
        }
0 comments