New to Telerik UI for WPF? Download free 30-day trial

Get cell from Point

This article describes how you can get a cell index by using a specific location on the screen.

In order to get the cell under the mouse you need the position related to the top left corner of the grid that contains all cells. This is why you need to get the position relative to the WorksheetEditorPresenter. Then you can use the GetCellIndexFromViewPoint method to get the cell under the mouse.

Example 1: Get the cell under the mouse

private void MainWindow_Loaded(object sender, RoutedEventArgs e) 
{ 
    var worksheetEditor = this.radSpreadsheet.ActiveWorksheetEditor; 
    if (worksheetEditor != null) 
    { 
        var presenter = worksheetEditor.ActivePresenter as NormalWorksheetEditorPresenter; 
        presenter.PreviewMouseMove += Presenter_PreviewMouseMove; 
    } 
} 
 
private void Presenter_PreviewMouseMove(object sender, MouseEventArgs e) 
{ 
    var presenter = sender as NormalWorksheetEditorPresenter; 
    Point position = e.GetPosition(presenter); 
 
    CellIndex clickedCellIndex = presenter.GetCellIndexFromViewPoint(position); 
    string clickValue = String.Format("Hovered!"); 
    this.radSpreadsheet.ActiveWorksheet.Cells[clickedCellIndex].SetValue(clickValue); 
} 
In this article