This is a migrated thread and some comments may be shown as answers.

ClipboardCopyMode="Cells" not working quite as expected

5 Answers 453 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Christoph
Top achievements
Rank 1
Christoph asked on 11 Aug 2011, 07:16 AM
Because I got stuck I looked at the following example:

http://www.telerik.com/community/forums/wpf/gridview/copying-cell-content-problem.aspx

Using that example: When I go into edit mode for a cell, I can copy the cell's content. When I only select the cell without going into edit mode (still seeing a selection rectangle), it is called three times and in the end copies the entire row to the clipboard.

However, what I want is to copy only the current cell's content to the clipboard without having to go into edit mode (my grid happens to be read only). Bonus: can I get a context menu over the cell for copy? (without too much effort)

Thanks,
 Chris

5 Answers, 1 is accepted

Sort by
0
Christoph
Top achievements
Rank 1
answered on 11 Aug 2011, 07:32 AM
I came up with some sort of solution for Ctrl+C:

void PitGridView_CopyingCellClipboardContent(object sender, GridViewCellClipboardEventArgs e)
{
    if (CurrentCell != null && CurrentCell.Column == e.Cell.Column)
    {
        e.Cancel = false;
    }
    else
        e.Cancel = true;
}

I don't really consider this to be elegant or intuitive (Cells copy mode should be working this way by default), but it works.

Context menu question still open.

Chris
0
Yavor Georgiev
Telerik team
answered on 12 Aug 2011, 08:02 AM
Hello Christoph,

 ClipboardCopyMode=Cells will always try to copy all the selected items, based on the value of the SelectionUnit property of RadGridView. If SelectionUnit=FullRow, RadGridView will copy whole rows, whereas if SelectionUnit=Cell RadGridView will copy individual cells.

 From what I understand in your case, you have SelectionUnit=FullRow (the default), but would only like to copy one cell. What you can do is to either set SelectionUnit to Cell and change the way selection works, or keep using your workaround in the CopyingCellClipboardContent event.

 Regarding the context menu question: I believe this example will help you get started. Even though it's for Silverlight, you can use the same code in your WPF application. Or you can find this example in the RadControls for WPF Demos application that was installed along with RadControls for WPF. Don't hesitate to let us know if you have any difficulties in implementing it in your application.

All the best,
Yavor Georgiev
the Telerik team

Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get now >>

0
Christoph
Top achievements
Rank 1
answered on 16 Aug 2011, 06:13 AM
Regarding the context menu - I already have one for the header (column visibility, also from the samples). What is the best way to have 'two different' context menus on the GridView?

Chris
0
Maya
Telerik team
answered on 16 Aug 2011, 08:14 AM
Hello Christoph,

In case you want to have both row and header context menus, you may follow the approach illustrated in this forum thread. If you want to apply specific logic depending on the underlying item or cell, you may handle the Opening event of the RadContextMenu and perform it inside.
Let me know in case you need any further assistance.

 

Greetings,
Maya
the Telerik team

Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get now >>

0
Christoph
Top achievements
Rank 1
answered on 16 Aug 2011, 09:16 AM
I went with a switch in the Opening event based on the type of cell the context menu was opened on.

Chris
Tags
GridView
Asked by
Christoph
Top achievements
Rank 1
Answers by
Christoph
Top achievements
Rank 1
Yavor Georgiev
Telerik team
Maya
Telerik team
Share this question
or