Hi,
We are looking to extend the functionality on spreadsheet control reset dirty changes to original state. However, we have a minor problem with reset since it always resets to active tab to a template active sheet.
Based on example in previous forum question I've added another sheet Sheet2 to the Test.xlsx file and saved the file. The file's active sheet now in template is Sheet2, but after reload I want to change the selected worksheet tab to Sheet1. Ideally, if this sheet had a long list of data, the scroll position also should remain after reloading. The sample does not have additional reset button. However once the reset is clicked all changes discarded (this already works for us) but additional information should be kept. The information like previous selected active sheet and scroll position
Please provide suggestion how to achieve this. Thanks in advance.
best regards,
Tomas
Hello Tomas,
I have been looking into your requirement and prepared a small sample to demonstrate resetting the XamSpreadsheet’s ActiveWorksheet and scrolling a particular cell or cell range into view.
You could change the selected worksheet in the following way:
this.spreadSheet.ActiveWorksheet = this.spreadSheet.Workbook.Worksheets["Sheet1"];
Regarding the scroll position, I noticed that when toggling between worksheets, including manually resetting the active worksheet or loading the workbook, the worksheet's past scroll position remains. For example, when clicking the “Reset to Sheet1” its scroll position is the same as it was before changing to, for example to “Sheet2”. However, if you want to have control over a particular cell, or cell region coming into view, my suggestion is to retrieve either the last active SpreadsheetCell or SpreadsheetCellRange from the spreadsheet’s ActivePane property:
public partial class MainWindow : Window { SpreadsheetCell lastActiveCell; SpreadsheetCellRange lastSpreadsheetCellRange; Worksheet lastActiveWorksheet; //… private void SaveLastActiveWorksheetItems() { this.lastActiveCell = spreadSheet.ActiveCell; this.lastActiveWorksheet = spreadSheet.ActiveWorksheet; this.lastSpreadsheetCellRange = spreadSheet.ActivePane.VisibleRange; }
And in order to scroll to the saved cell or range you can use the ActivePane’s ScrollRangeIntoView/ScrollCellIntoView methods:
private void ScrollLastReionIntoView() { this.spreadSheet.ActivePane.ScrollRangeIntoView(this.lastSpreadsheetCellRange); //this.spreadSheet.ActivePane.ScrollCellIntoView(this.lastActiveCell); }
In the sample, I am not reproducing your exact reset scenario, however, for the purposes of the example I have added the “Reset to Sheet1 and handle scroll position” button as well. I am saving the last active worksheet, cell and cell region before resetting to “Sheet1”. After resetting to it, I scroll “Sheet1” to the region that was visible in the sheet that was active before.
I hope that using similar techniques, you will be able to achieve your requirement.
You can find the sample attached below. If this is not an accurate demonstration of what you are trying to achieve please feel free to modify it and send it back to me along with steps to reproduce. If you require any further assistance on the matter, please let me know.
Sincerely,
Bozhidara Pachilova
Associate Software Developer
2538.XSLoadPreviousActiveSheet.zip