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

Detecting which cell was clicked/focused

1 Answer 130 Views
Spreadsheet
This is a migrated thread and some comments may be shown as answers.
Edward
Top achievements
Rank 1
Edward asked on 14 Jun 2014, 05:56 AM
Is there way to detect which cell (row, col) that was just either left mouse button clicked or focused...

1 Answer, 1 is accepted

Sort by
0
Deyan
Telerik team
answered on 18 Jun 2014, 04:19 PM
Hello Edward,

Thank you for contacting us about this issue!
 
You can subscribe to the SelectionChanged event and check which the current selection active cell index is. Here follows a code snippet demonstrating how you can achieve that: 

private RadWorksheetEditor editor = null;
 
private RadSpreadsheet RadSpreadsheet
{
    get
    {
        return this.radSpreadsheet;
    }
}
 
private void OnInitialized()
{
    this.RadSpreadsheet.ActiveSheetEditorChanged += ActiveSheetEditorChanged;
    this.AttachToSelectionChanges();
}
 
private void ActiveSheetEditorChanged(object sender, EventArgs e)
{
    this.AttachToSelectionChanges();
}
 
private void AttachToSelectionChanges()
{
    if (this.editor != null)
    {
        this.editor.Selection.SelectionChanged -= SelectionChanged;
    }
 
    this.editor = this.RadSpreadsheet.ActiveWorksheetEditor;
 
    if (this.editor != null)
    {
        this.editor.Selection.SelectionChanged += SelectionChanged;
    }
}
 
private void SelectionChanged(object sender, EventArgs e)
{
    if (this.editor != null)
    {
        Debug.WriteLine("SelectionChanged with ActiveCellIndex: {0}", this.editor.Selection.ActiveCellIndex);
    }
}

A few words on this code snippet:
  • Have in mind that you should call OnInitialized method in your main page constructor where you can access the instance of the RadSpreadsheet control. 
  • When the selection changes the active cell index is logged in the output which may be seen in SelectionChanged method.

 I hope this is helpful. If you have any other questions or concerns please do not hesitate to contact us again.

Regards,
Deyan
the Telerik team
 
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.
 
Tags
Spreadsheet
Asked by
Edward
Top achievements
Rank 1
Answers by
Deyan
Telerik team
Share this question
or