This is a migrated thread and some comments may be shown as answers.

Possible to paste a single value across multiple cells?

1 Answer 326 Views
GridView
This is a migrated thread and some comments may be shown as answers.
LT
Top achievements
Rank 1
LT asked on 06 Mar 2019, 11:01 AM

In Excel, holding onto a single value, you can paste it across all cells of a rectangle that you draw. I would like to duplicate this behavior with radGridView. Is it possible? I have tried it in my own program but it doesn't seem that the value is pasted across all cells selected, just the first one that was clicked on.

1 Answer, 1 is accepted

Sort by
0
Accepted
Dess | Tech Support Engineer, Principal
Telerik team
answered on 07 Mar 2019, 01:19 PM
Hello,    

The described behavior is supported by RadSpreadsheet that the Telerik UI for WinForms suite offers. You can select a cell in the spreadsheet, right click to select Copy. Then, select a cells region, right click and select Paste. Thus, the copied value will be pasted among the selected cells.

As to the RadGridView, it allows pasting over a single cell. If you need to affect all selected cells with the copied value, it would be necessary to handle the Pasting event and perform the desired action. A sample approach is demonstrated in the following code snippet:

public RadForm1()
{
    InitializeComponent();
 
    for (int i = 0; i < 3; i++)
    {
        this.radGridView1.Columns.Add("Col" + i);
    }
    for (int i = 0; i < 10; i++)
    {
        this.radGridView1.Rows.Add("Data" + i + ".0", "Data" + i + ".1", "Data" + i + ".2");
    }
    this.radGridView1.AutoSizeColumnsMode = Telerik.WinControls.UI.GridViewAutoSizeColumnsMode.Fill;
    this.radGridView1.MultiSelect = true;
    this.radGridView1.SelectionMode = Telerik.WinControls.UI.GridViewSelectionMode.CellSelect;
 
    this.radGridView1.Pasting += radGridView1_Pasting;
}
 
private void radGridView1_Pasting(object sender, Telerik.WinControls.UI.GridViewClipboardEventArgs e)
{
    e.Cancel = true;
    if (e.Format == "Text")
    {
        string data = Clipboard.GetData(DataFormats.Text).ToString();
        if (data != null)
        {
            foreach (GridViewCellInfo cell in this.radGridView1.SelectedCells)
            {
                cell.Value = data;
            }
        }
    }
}

I hope this information helps. If you need any further assistance please don't hesitate to contact me. 

Regards,
Dess | Tech Support Engineer, Sr.
Progress Telerik
Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
Tags
GridView
Asked by
LT
Top achievements
Rank 1
Answers by
Dess | Tech Support Engineer, Principal
Telerik team
Share this question
or