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
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

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

Thread ID:





142349 Jan 29,2019 01:37 PM UTC Jan 30,2019 11:27 AM UTC WPF 1
Tags: GridControl
Jonathan Bleeker
Asked On January 29, 2019 01:37 PM UTC


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?

Jagadeesan Pichaimuthu [Syncfusion]
Replied On 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. 

gridControl.Model.ClipboardPaste += Model_ClipboardPaste; 
private void Model_ClipboardPaste(object sender, GridCutPasteEventArgs e) 
    var copiedText = Clipboard.GetText(); 
    var splittext = copiedText.Split(new String[] { "\r\n" }, 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. 



This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

Please sign in to access our forum

This page will automatically be redirected to the sign-in page in 10 seconds.

Warning Icon You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.Close Icon

Live Chat Icon For mobile
Live Chat Icon