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

Radspreadsheet Copy Paste & Context Menu's

8 Answers 383 Views
Spreadsheet
This is a migrated thread and some comments may be shown as answers.
Rod
Top achievements
Rank 1
Rod asked on 03 Sep 2014, 05:36 PM
I have several questions regarding copy paste within a RadSpreadsheetControl
1) I have a ViewModel that is set as the Datacontext of the usercontrol.  This VM controls many of the IsEnabled, IsVisible properties of the spreadsheet Control itself.  BUT in order to get the Context Menu and commands working, I have to reset the Datacontext of the radspreadsheet control to
                    DataContext="{Binding Path=CommandDescriptors, ElementName=radSpreadsheet}"  Is there a way to hook this all up w/o changing the DataContext of the RadSpreadsheetControl?

2) In order to get copy paste to work with <ctrl/shift>+Insert, I have to  Re-Register the inputBinding as such (Is this correct - it kinda works but may be the result of my other problem) - Why isn't this gesture automatically hooked up for the spreadsheet control like it is with the other editors within Telerik?
CommandManager.RegisterClassInputBinding(typeof(RadWorksheetEditor), new InputBinding(radSpreadBudgetSheet.CommandDescriptors.Copy.Command, new KeyGesture(Key.Insert, ModifierKeys.Control)));
CommandManager.RegisterClassInputBinding(typeof(RadWorksheetEditor), new InputBinding(radSpreadBudgetSheet.CommandDescriptors.Paste.Command, new KeyGesture(Key.Insert, ModifierKeys.Shift)));

3)  Since my radspreadsheet control contains data that I am storing in the database, I have hooked up the CellPropertyChanged event to monitor when things have changes and update my ViewModel.  But when the command is executed I am getting a range of MY ENTIRE SPREADSHEET in the CellPropertyChanged event.  This event is getting hammered because nearly every property is getting changed (protection, formatting, etc) when a cell is pasted.  Interestingly enough, if I go into a single cell, press F2 then "copy" (a cell value changed gets triggered here too!) then navigate to another cell press F2, then paste - I get a cell value changed for a single cell.  HOW CAN I get only the range of cells that was changed with the paste operation, not the entire spreadsheet!

8 Answers, 1 is accepted

Sort by
0
Accepted
Anna
Telerik team
answered on 04 Sep 2014, 02:18 PM
Hello Rod,

At this point you do need to set the data context of the RadSpreadsheet in order for the commands to work. Is there anything in your scenario which makes setting the data context problematic?

Thank you for pointing out the ctrl/shift + insert input bindings. We have included these in the default input bindings of RadSpreadsheet and they will be included in the next LIB. If you would like to add them yourself in the meantime, or in case you need this for future reference, RadSpreadsheet has its own KeyBindings collection. You need code similar to this:

var editor = this.radSpreadsheet.ActiveWorksheetEditor;
 
editor.KeyBindings.RegisterCommand(editor.Commands.Copy, Key.Insert, ModifierKeys.Control);
editor.KeyBindings.RegisterCommand(editor.Commands.Paste, Key.Insert, ModifierKeys.Shift);

 

I was able to reproduce the issue with the cell range provided by the CellPropertyChanged event using the service pack version of the control. However, it seems that it has been solved with the LIB released in the beginning of this week. Can you download it and get back to me if you still have the same problem?

By the way, if you are interested in the change of a particular property only, you can try the following:

private void Cells_CellPropertyChanged(object sender, CellPropertyChangedEventArgs e)
{
    if (e.Property == CellPropertyDefinitions.ValueProperty)
    {
        //...
    }
}

I hope this helps.

Regards,
Anna
Telerik
 
Check out Telerik Analytics, the service which allows developers to discover app usage patterns, analyze user data, log exceptions, solve problems and profile application performance at run time. Watch the videos and start improving your app based on facts, not hunches.
 
0
Rod
Top achievements
Rank 1
answered on 04 Sep 2014, 02:53 PM
Thanks for the response.  I will add in the KeyBindings as specified above! 

I will not be able to get the latest LIB as the development team is tied to our current version and I have some deadline for late next week to complete this project.  I have also changed the way I transfer data between my VM and the RadSpreadsheet to eliminate that issue.

Setting the datacontext is problematic because I have a ViewModel that I am currently binding the IsEnabled and IsVisible properties of the RadSpreadsheet too.  Granted I could add the RadSpreadsheet to my VM and handle the Visible and Enabled property programmatically, but its a workaround.  I understand that you need the Datacontext setting so that you can have access to various other parts and pieces.  Why couldn't you add a new dependency property to the RadSpreadsheet so it can have access to the commandDescriptors?

I was already utilizing the CellPropertyDefinitions within the cellPropertyChanged Event - but thank you for the reference again.

(One post answered - 2 to go) 
0
Anna
Telerik team
answered on 08 Sep 2014, 12:52 PM
Hi,

If you would like to avoid inserting the entire RadSpreadsheet in your view model, you can use only the command descriptors. You can preserve their behavior by two attached properties, which will update them in your view model. I am attaching a sample project which illustrates what I have in mind.

Regards,
Anna
Telerik
 
Check out Telerik Analytics, the service which allows developers to discover app usage patterns, analyze user data, log exceptions, solve problems and profile application performance at run time. Watch the videos and start improving your app based on facts, not hunches.
 
0
Rod
Top achievements
Rank 1
answered on 08 Sep 2014, 04:14 PM
Anna,
  This works in general, BUT NOT in my specific case.  IT appears there is an issue  when a spreadsheet is imported.  Please see my attached example - All I did was remove the FormulaBar and the status bar and added a button that loads a spreadsheet template.

Run the example, and first verify that the copy paste context menu works (it should), then click the 'load template' button and try the context menu.  the context menu is not displaying properly and doesn't work.
0
Anna
Telerik team
answered on 11 Sep 2014, 01:29 PM
Hello Rod,

I assume you are talking about the fact that the only item present in the menu is "copy" when the locked cells of your file are clicked and "copy" and "clear contents" when the unlocked cells are clicked. As in the other thread you've created, the reason is the protection and you will notice this behavior in any RadSpreadsheet, not just in your project. The IsEnabled property of the other context menu items is permanently set to false when the sheet is protected, regardless of the IsLocked property of the currently selected cells.

If you would like to, you can replace the IsEnabled property of the items. However, please, keep in mind that if the wrong item is made available this might give the user an option to change a protected part of the sheet. For example, even if the currently selected cell is not protected, if you paste a larger range, this may change a protected cell.

Regards,
Anna
Telerik
 
Check out Telerik Analytics, the service which allows developers to discover app usage patterns, analyze user data, log exceptions, solve problems and profile application performance at run time. Watch the videos and start improving your app based on facts, not hunches.
 
0
Rod
Top achievements
Rank 1
answered on 11 Sep 2014, 03:09 PM
So, why does the radSpreadsheet Honor the Protected and IsLocked property for general editing purposes BUT it doesn't honor it when doing copy paste from context menu or navigation?    In addition it works with ctrl+c and ctrl+v but not from the contect menus?

Try this and you will see my frustration.

go and select a set of 2 or 3 unlocked cells of my loaded template (they will have a white background) and press ctrl+c
then move to another area of white background and press ctrl+v.  THE DATA IS COPIED AND PASTED PROPERLY!

Now, go to a set of protected cells (grey or grey hashed background) and try to ctrl+v - You will get the protected cells popup.

SO, I again ask - why does the functionality work one way (ctrl+C ctrl+V) but it does not work with the copy paste context menu. 

0
Accepted
Anna
Telerik team
answered on 12 Sep 2014, 02:43 PM
Hello,

I tried your example and you are correct, thank you for pointing this issue out. I am going to update the IsEnabled properties for the Cut, Paste and Clear commands so that they will be visible in the context menu regardless of the protection. I will also ensure that the locked cell of the worksheet are protected, even if these items are visible. The rest of the context menu items are not available in Excel when the sheet is protected, so I assume it is those three that you are concerned about. This change will be available in one of the next LIBs.

Even if you are unable to download the LIB, you can freely set the IsEnabled property of the Paste context menu item to "true", as you were correct in pointing out that the user will get the protected cells popup if they try to paste over a protected cell. You can also enable the Cut command. The user will not get the protected cells popup when cutting a protected cell (this will be fixed in the LIB), but the content of the cells will not be removed. It would be best not to enable the Clear command however, as the protection from clearing the selected cells, which will be available in the LIB, is not present in your version of the control.

Regards,
Anna
Telerik
 
Check out Telerik Analytics, the service which allows developers to discover app usage patterns, analyze user data, log exceptions, solve problems and profile application performance at run time. Watch the videos and start improving your app based on facts, not hunches.
 
0
Rod
Top achievements
Rank 1
answered on 12 Sep 2014, 05:24 PM
Thanks for sticking with me on this thread Anna, it is much appreciated. 
the solution above has allowed me to get all the needed functionality into the application I am working on at this time.  Once we upgrade to the new LIB's, I can go back and alter a few lines of code and everything should work properly.

Thanks
Again - Rod
Tags
Spreadsheet
Asked by
Rod
Top achievements
Rank 1
Answers by
Anna
Telerik team
Rod
Top achievements
Rank 1
Share this question
or