I am trying to set focus on a specific Cell in the active sheet using spread Spreadsheet component and documents APIs. However I can not find any method to do this.
I would like to scroll to cell if it is out of site.
I am trying to set focus on a specific Cell in the active sheet using spread Spreadsheet component and documents APIs. However I can not find any method to do this.
I would like to scroll to cell if it is out of site.
There is no single FocusCell method, but you can do it in three steps with the existing APIs:
Selection.RadzenSpreadsheet.ScrollToAsync.<RadzenButton Text="Go to Z150" Click=@GoToCell />
<RadzenSpreadsheet @ref=@spreadsheet Workbook=@workbook Style="height: 400px" />
@code {
RadzenSpreadsheet spreadsheet;
Workbook workbook = new Workbook();
async Task GoToCell()
{
var sheet = workbook.Sheets[spreadsheet.SelectedSheetIndex];
var cell = CellRef.Parse("Z150");
sheet.Selection.Select(cell);
await spreadsheet.ScrollToAsync(cell);
await spreadsheet.Element.FocusAsync();
}
}
Selection.Select moves the active cell and the selection outline. ScrollToAsync only scrolls if the cell is outside the visible area, and it accounts for frozen rows and columns. Element.FocusAsync() puts keyboard focus on the spreadsheet, so pressing an arrow key afterwards moves from Z150.
You can also use new CellRef(row, column) with zero-based indices instead of CellRef.Parse, and Selection.Select(RangeRef.Parse("B2:D5")) to select a range.