We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date

Get cell row/column ID for each cell on paste event

Hi

I would like to examine the data on a per cell basis during a paste event when pasting into a large group of cells, with the type of tests depending on cell row/column.

I am looking at the ClipboardPaste event and things seem to be a bit obscure in this regard.

Any suggestions?

1 Reply

JP Jagadeesan Pichaimuthu Syncfusion Team January 30, 2019 11:27 AM UTC

Hi Jonathan, 

Thanks for using Syncfusion product. 

To pasted the cell value based on the cell format, you could use the ClipboardPaste event. Please refer the following code example to meet your requirement. 

C# 
gridControl.Model.ClipboardPaste += Model_ClipboardPaste; 
private void Model_ClipboardPaste(object sender, GridCutPasteEventArgs e) 
{ 
    var copiedText = Clipboard.GetText(); 
    var splittext = copiedText.Split(new String[] { "\r" }, StringSplitOptions.None).ToList<object>(); 
    splittext = splittext.Where(x => !String.IsNullOrEmpty(x.ToString())).ToList<object>(); 
    for (int i=0;i<splittext.Count;i++) 
    { 
        splittext[i] = splittext[i].ToString().Split(new String[] { "\t" }, StringSplitOptions.None).ToArray(); 
    } 
    var currentCellRange = e.RangeList; 
 
    var pastingCellRange = GridRangeInfo.Cells(e.RangeList.ActiveRange.Top, e.RangeList.ActiveRange.Left, (e.RangeList.ActiveRange.Bottom + splittext.Count-1), (e.RangeList.ActiveRange.Right + (splittext[0] as String[]).Length - 1)); 
 
    for (int k = pastingCellRange.Top; k <= pastingCellRange.Bottom; k++) 
    { 
        for(int l=pastingCellRange.Left;l<=pastingCellRange.Right;l++) 
        { 
            GridStyleInfo style = gridControl.Model[k, l]; 
            if (style.CellValueType == typeof(double)) 
            { 
                string text = (splittext[k - pastingCellRange.Top] as String[])[l - pastingCellRange.Left]; 
                double value; 
                if (double.TryParse(text, out value)) 
                { 
                    if (!string.IsNullOrEmpty(style.Format)) 
                    { 
                        style.CellValue = string.Format("{0:" + style.Format + "}", value); 
                    } 
                } 
            } 
        } 
    } 
    e.Handled = true; 
} 
 

Please get back us if you need any further assistance on this. 

Regards, 
Jagadeesan

Loader.
Live Chat Icon For mobile
Up arrow icon