Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
595
Modify clipboard in pasting event
posted

Hi, When the cells from xamdatagrid are copied and pasted, I want to modify the contents of it. Is it possible? Please explain.

For example, if the copied cell content is "remove this text", then i want to change it to "text".

Parents
No Data
Reply
  • 6365
    Verified Answer
    Offline posted

    Hello Ramesh,

    In order to modify the Clipboard data, you can use the GetText and SetText methods of the System.Windows.Clipboard static class itself.

    By handling the PreviewKeyDown event of the XamDataGrid, you can manipulate the Clipboard data if the “Ctrl + V” combination has been used and if there is a currently ActiveCell. This way the following pasting operation will be performed by using the modified Clipboard data.

    XAML:

    <igDP:XamDataGrid x:Name="dataGrid" DataSource="{Binding Items}" PreviewKeyDown="dataGrid_PreviewKeyDown">
        <igDP:XamDataGrid.FieldLayoutSettings>
            <igDP:FieldLayoutSettings AllowClipboardOperations="All" />
        </igDP:XamDataGrid.FieldLayoutSettings>           
    </igDP:XamDataGrid>

    Code-behind:

    private void ModifyClipboardData()
    {
        var data = Clipboard.GetText();
        var newData = data.Substring(data.LastIndexOf(' ') + 1);
        Clipboard.SetText(newData);
    }

    private void dataGrid_PreviewKeyDown(object sender, KeyEventArgs e)
    {
        if (e.Key == Key.V && Keyboard.Modifiers == ModifierKeys.Control && (sender as XamDataGrid).ActiveCell != null)
        { 
            ModifyClipboardData();
        }
    }
     
    I have attached a sample application, where the approach from above has been used.

    If you require any further assistance on the matter, please let me know.

    XamDataGrid_manipulatingClipboardData.zip
Children
No Data