Detecting which cell was clicked/focused

2 posts, 0 answers
  1. Edward
    Edward avatar
    13 posts
    Member since:
    Oct 2013

    Posted 14 Jun 2014 Link to this post

    Is there way to detect which cell (row, col) that was just either left mouse button clicked or focused...

  2. Deyan
    Admin
    Deyan avatar
    136 posts

    Posted 18 Jun 2014 Link to this post

    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.
     
  3. DevCraft banner
Back to Top