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

Catch the radSpreadsheet.CommandDescriptors.SaveFile.Command event

5 Answers 190 Views
Spreadsheet
This is a migrated thread and some comments may be shown as answers.
Patrick
Top achievements
Rank 2
Patrick asked on 21 Jul 2016, 09:11 PM

Hi,

 

I want to be able to receive the file and/or set the file for the radSpreadsheet.CommandDescriptors.SaveFile.Command  command. It appears that no event can be handled before or after the command is executed.

 

Thanks

5 Answers, 1 is accepted

Sort by
0
Nikolay Demirev
Telerik team
answered on 25 Jul 2016, 08:24 AM
Hi Patrick,

You could create a custom save command and bind it to the Save button command. This way you won't use the default command descriptor and you will be able to handle the opened file.

Here is the default command implementation which you could use in your custom command:
SaveFileDialog saveFileDialog = new SaveFileDialog();
saveFileDialog.Filter = FileDialogsHelper.GetSaveFileDialogFilter();
  
saveFileDialog.FileName = editor.Owner.Workbook.Name;
  
if (saveFileDialog.ShowDialog() == true)
{
    string extension = Path.GetExtension(saveFileDialog.SafeFileName);
    using (Stream output = saveFileDialog.OpenFile())
    {
        WorkbookFormatProvidersManager.Export(editor.Owner.Workbook, extension, output);
    }
}

I hope this helps.

Regards,
Nikolay Demirev
Telerik by Progress
Do you need help with upgrading your AJAX, WPF or WinForms project? Check the Telerik API Analyzer and share your thoughts.
0
Coopbase
Top achievements
Rank 2
Iron
Iron
answered on 05 Apr 2021, 07:57 AM

I am struggling on this at this moment.

 

How to create "custom command". I am playing with sample Spreadsheet that comes with Telerik UI for WPF template > Excel.

 

1. I want to change Ctrl + S to route to new methods that I created.

2. I want to change the Command="{Binding Path=SaveFile.Command}"

So far, what I have seen are old samples based on SilverLight.  

 

thank you very much,

 

Rene

 

0
Coopbase
Top achievements
Rank 2
Iron
Iron
answered on 05 Apr 2021, 10:03 AM
Ignore this post.  I got it, finally.  I overthink.  Thanks.
0
Robby
Top achievements
Rank 1
answered on 14 Apr 2021, 04:48 PM

Hi,

Can you give more info how to create a custom save command to overwrite the default save behaviour?

Thanks

0
Tanya
Telerik team
answered on 19 Apr 2021, 11:44 AM

Hi,

In RadSpreadsheet you can customize the command descriptors for the key bindings and insert the desired logic there:

private void RadSpreadsheet_ActiveSheetEditorChanged(object sender, EventArgs e)
{
    if (this.radSpreadsheet.ActiveWorksheetEditor != null)
    {
        this.radSpreadsheet.ActiveWorksheetEditor.KeyBindings.RegisterCommand(new DelegateCommand(p => { SaveCommandHandler(); }), Key.S, ModifierKeys.Control, null);
    }
}

In the above example, the SaveCommandHandler() method should contain the logic that needs to be executed when users press Ctrl+S, or you can pass null if you don't need to execute anything. Please, note that this modification of the bindings should be applied when the ActiveSheetEditor is changed.

If you are using the ribbon of RadSpreadsheet, you can expand its XAML code and directly modify the buttons there or add new ones.

Hope this is helpful.

Regards,
Tanya
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.

Robby
Top achievements
Rank 1
commented on 13 Aug 2021, 09:28 AM

Hi,

This solution does not catch the save button on the quick access bar and in the application menu. We want to catch all possible save actions in the software.

Regards,

Robby

Dimitar
Telerik team
commented on 16 Aug 2021, 08:15 AM

Hi Robby, 

This should be handled separately. Once the editable XAML of the ribbon is extracted (see the above post). You can assess the save buttons and bind the custom commands or handle their click events. I have attached some screenshots that show this as well. 

Let me know if I can assist you further.
Tags
Spreadsheet
Asked by
Patrick
Top achievements
Rank 2
Answers by
Nikolay Demirev
Telerik team
Coopbase
Top achievements
Rank 2
Iron
Iron
Robby
Top achievements
Rank 1
Tanya
Telerik team
Share this question
or