Adding paste special support

7 posts, 0 answers
  1. Paw
    Paw avatar
    8 posts
    Member since:
    Mar 2010

    Posted 25 Nov 2010 Link to this post

    Hi.

    I have an application with a listview. Each listview item is templated showing additional information . Basically each listview items contains one image and several values like timestamps, string, ints.

    The listview can be filtered using radDataFilter, and I want to be able to select an item in the listview, copy the item (I use my own clipboard format), go into the filter and then paste one of the copied values from my custom formattet content in the clipboard. I want to prompt the user with a dialog to choose with exact information to actually paste from the clipboard. And the content of clipboard should remain after the radDataFilter pasing.

    My first approch to this has been to do it like this (simplified code):

    private void filter_EditorCreated(object sender, Telerik.Windows.Controls.Data.DataFilter.EditorCreatedEventArgs e)
    {
        DataObject.AddPastingHandler(e.Editor, new DataObjectPastingEventHandler(CheckPasteFormat));
    }

    public void CheckPasteFormat(object sender, DataObjectPastingEventArgs e)
    {
     PasteWindow win = new PasteWindow();
     win.ShowDialog(); // Modal dialog
     string result = win.Value.ToString();
      
     DataObject d = new DataObject();
     d.SetData(DataFormats.Text, result);
     e.DataObject = d;
    }

    The problem with this solution is that showing a new window or as test just call MessageBox.Show gives an error:

    Cannot perform this operation while dispatcher processing is suspended.

    I have found a solution to this using Dispather.BeginInvoke but this has another problem with the folowing part updating the DataObject due to it is asynchroniously. There might be solutions to this also, but it gives me a feeling of a lot of hacks to make it work

    So my next approach (and maybee more correct solution) would be to define a new "Paste special" command/functionality to handle my special pasting inside editor. Actually kind of the same way as Word, Excell etc does it, Im not very familiar with commands and stuff like that. Can you tell me if it is possible to add/append a "paste special" command with keyboard shortcut to the radDataFilter editors. It should also be available using the right-click menu in the radDataFilter editors.

    Hopefully the "Speciel paste" will support undo etc, and clipboard content should not be changed using the "Speciel paste".

    Hopefully you will be able to help me with this one.

  2. Yavor Georgiev
    Admin
    Yavor Georgiev avatar
    982 posts

    Posted 26 Nov 2010 Link to this post

    Hi Paw,

     Unfortunately, I was not able to reproduce the Dispatcher error. Could you please open a support ticket and attach your application, or at least a sample application that demonstrates the problem, so that we may examine it and try to determine a solution?

    All the best,
    Yavor Georgiev
    the Telerik team
    Browse the videos here>> to help you get started with RadControls for WPF
  3. UI for WPF is Visual Studio 2017 Ready
  4. Paw
    Paw avatar
    8 posts
    Member since:
    Mar 2010

    Posted 26 Nov 2010 Link to this post

    Hi.

    Thanks for the quick reply. Just to let you know the dispather problem is a WPF problem - not at telerik problem. I have an ongoing thread at MSDN discussing this proplem. You can find it here:

    http://social.msdn.microsoft.com/Forums/en-US/wpf/thread/2e9b920c-c5d8-4d6c-a1fa-9fee87f90546

    But I would like you oppinion on the second solution. Do you see a way to add a custom command "Paste Special" to all Editor element in the radDataFilter.

    The functionality will be coded by me and is quite simple. I will collect some custom elements from the clipboard, prompt the user to select which text part to insert/paste in the editor. One thing to keep in mind is the actually pasting. The content of the clipboard should stay untouched after the "Paste Special" is fired.

    Would it be okay for you if I attach a demo application here in this thread?
  5. Yavor Georgiev
    Admin
    Yavor Georgiev avatar
    982 posts

    Posted 26 Nov 2010 Link to this post

    Hello Paw,

     If you wish, you can certainly attach a context menu to the editor in the EditorCreated event and populate that menu with whatever entries you need, etc. You have full access to the filter editor in the event, you won't even need to interact with RadDataFilter.

    Greetings,
    Yavor Georgiev
    the Telerik team
    Browse the videos here>> to help you get started with RadControls for WPF
  6. Paw
    Paw avatar
    8 posts
    Member since:
    Mar 2010

    Posted 26 Nov 2010 Link to this post

    Do you have a code sample that shows how to do it?

    And what about the string that should be pasted. What do you recomment. Using clipboard (then I should be able to backup/restore clipboard content) or are there an easy way to do the pasting by code in all type editors (IInputElements)?

    Thanks in advance
  7. Paw
    Paw avatar
    8 posts
    Member since:
    Mar 2010

    Posted 26 Nov 2010 Link to this post

    I have created a support ticket and attached my demo application
  8. Yavor Georgiev
    Admin
    Yavor Georgiev avatar
    982 posts

    Posted 29 Nov 2010 Link to this post

    Hi Paw,

     I think the MSDN approach is good. However, pasting does not work because you're executing it on the editor itself. The editor in RadDataFilter is not the TextBox, but rather the visual element, which contains the TextBox and the "match case" toggle button. You need to get the original source (e.OriginalSource) of the pasting event, not the sender. The original source is always the TextBox or other editing element.

    Best wishes,
    Yavor Georgiev
    the Telerik team
    Browse the videos here>> to help you get started with RadControls for WPF
Back to Top
UI for WPF is Visual Studio 2017 Ready