Copying entire VirtualGrid to Clipboard. Row and Column index never change

1 Answer 81 Views
VirtualGrid
Joe
Top achievements
Rank 2
Iron
Iron
Veteran
Joe asked on 19 Sep 2021, 08:10 PM

I've got a Virtual Grid with 29 rows of data and 3 columns.  I want to have a function that copies all of its contents to the clipboard.  My handler looks like this:

    private void RadMenuItem_OnClick(object sender, RadRoutedEventArgs e)
    {
        // Select all cells and then copy them to the clipboard
        VirtualGrid.SelectAll();
        VirtualGrid.CopyToClipboard();
    }

I wrote my event handler for the CopyingCellClipboardContent event to use the cell row and column index to return the data item for whatever cell was requested:


    private void VirtualGrid_OnCopyingCellClipboardContent(object? sender, VirtualGridCellClipboardEventArgs e)
    {

        if (TryGetCellString(e.Cell.RowIndex, e.Cell.ColumnIndex, out var s))
            e.Value = s; 

        Debug.WriteLine($"Copying cell {e.Cell.RowIndex}, {e.Cell.ColumnIndex} => \'{e.Value}\'");
    }

And sure enough, my handler was called 87 times (29 rows x 3 columns).  But every single time it was called, the row and column index was exactly the same -- whatever row and column I had last clicked.   here is some of my debug output





SelectedSellsChanged
Copying
Copying cell 1, 0 => '575.500, 1.000'
Copying cell 1, 0 => '575.500, 1.000'
Copying cell 1, 0 => '575.500, 1.000'
Copying cell 1, 0 => '575.500, 1.000'
Copying cell 1, 0 => '575.500, 1.000'
Copying cell 1, 0 => '575.500, 1.000'
Copying cell 1, 0 => '575.500, 1.000'
Copying cell 1, 0 => '575.500, 1.000'
Copying cell 1, 0 => '575.500, 1.000'


I can visually see the SelectAll() call selecting all the cells.  And my selection mode is Extended.  And it calls my handler the correct number of times.  

So why does it keep asking me for exactly the same cell all 87 times?  Shouldn't those row/column indices be changing?

 

 

1 Answer, 1 is accepted

Sort by
0
Accepted
Stenly
Telerik team
answered on 20 Sep 2021, 03:50 PM

Hello Joe,

This behavior was present on my side as well, and after testing the control, it seems that there is a bug in the CopyToClipboard method. That said, I have logged a bug report item in our feedback portal, that you can follow and get notified via e-mail when its status changes.

Also, as a token of gratitude, you can find your Telerik points updated for bringing this to our attention.

In conclusion, if you need help with anything else, please reach out to us. 

Regards,
Stenly
Progress Telerik

Love the Telerik and Kendo UI products and believe more people should try them? Invite a fellow developer to become a Progress customer and each of you can get a $50 Amazon gift voucher.

Joe
Top achievements
Rank 2
Iron
Iron
Veteran
commented on 21 Sep 2021, 12:11 AM

Thank you, Stenly.  In the meantime I have managed to figure out a workaround to the bug.   Since Telerik is calling my handler the correct number of times, I can make it work by just manually managing  a sequential index myself and calculating the row/column indices from it.  I increment it each time my handler is called

So given that I my data has a property called 'ColumnCount' that indicates the number of fields, I can copy all the data properly by changing my code to something like this:


    private int _copyIndex;  // Which row/cell is being requested?
    private void RadMenuItem_OnClick(object sender, RadRoutedEventArgs e)
    {
        // Select all cells and then copy them to the clipboard
        VirtualGrid.SelectAll();
        _copyIndex = 0;   
        VirtualGrid.CopyToClipboard();
    }


    private void VirtualGrid_OnCopyingCellClipboardContent(object? sender, VirtualGridCellClipboardEventArgs e)
    {
        var row = _copyIndex / ColumnCount; 
        var col  = _copyIndex % ColumnCount;
_copyIndex++; // increment for next time we're called if (TryGetCellString(row, col, out var s)) e.Value = s; Debug.WriteLine($"Copying cell {e.Cell.RowIndex}, {e.Cell.ColumnIndex} => \'{e.Value}\'"); }


Stenly
Telerik team
commented on 21 Sep 2021, 01:36 PM

Thank you for taking the time to share your solution with us. This will be of great help when our developers look more carefully into this matter. 
Tags
VirtualGrid
Asked by
Joe
Top achievements
Rank 2
Iron
Iron
Veteran
Answers by
Stenly
Telerik team
Share this question
or