RadGridView Pasting Get source cell

4 posts, 0 answers
  1. Anatol
    Anatol avatar
    2 posts
    Member since:
    Sep 2019

    Posted 05 Sep 2019 Link to this post

    Hello

    I use c# wpf telerik RadGridView and I have problem with Pasting. RadGridView`s cells contain my special custom type:

    class Place

    {

       int id;

       string name;

    }

    I need to get source cell in PastingCellClipboardContent to read Place.id:

    private void radGridView1_PastingCellClipboardContent(object sender, GridViewCellClipboardEventArgs e){

    if (e.Cell.Column.UniqueName == "Place"){

       //here i need source cell

    }

    How can I get it?

    Thanks

  2. Martin Ivanov
    Admin
    Martin Ivanov avatar
    2425 posts

    Posted 10 Sep 2019 Link to this post

    Hello Anatol,

    To achieve your requirement, you can get the data context of the cell using its Item property, and then find the Place's id from the data context's properties. Here is an example:

    private void radGridView1_PastingCellClipboardContent(object sender, GridViewCellClipboardEventArgs e){
    
    	if (e.Cell.Column.UniqueName == "Place")
    	{
    		var item = (MyModel)e.Cell.Item;
    		var id = item.Place.Id;
    	}
    }

    I also attached an example showing this approach. I hope it helps.

    Regards,
    Martin Ivanov
    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.
  3. Anatol
    Anatol avatar
    2 posts
    Member since:
    Sep 2019

    Posted 10 Sep 2019 in reply to Martin Ivanov Link to this post

    Thanks for reply!

    Sorry, may be I `ve discribed my problem wrongly. I would like to get access to SOURCE cell, not target cell.

    var item = (MyModel)e.Cell.Item; //It`s a tareget cell, which will be replaced with new data from source cell

    I found out I can get source data from e.Value, but it`s only object,  it contains only place.name, but doesn`t contain my place.Id.

     

  4. Martin Ivanov
    Admin
    Martin Ivanov avatar
    2425 posts

    Posted 11 Sep 2019 Link to this post

    Hello Anatol,

    No worries. The mistake here is main.

    The e.Value property from the PastingCellClipboardContent event arguments contains only the copied data string because during the copy of a cell only this is saved.  The reason behind this behavior is that the data should be readable from any application that supports pasting and usually those application doesn't have information for the RadGridView's cell or the underlying business object. 

    To achieve your requirement, you can use also the copy events of RadGridView (Copying, CopyingCellClipboardContent and Copied) where you can save information for the copied cell and use it in the PastingCellClipboardContent event.

    Regards,
    Martin Ivanov
    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.
Back to Top