Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
3186
Mousemove to cell location
posted

I would like to be able to show users what cell they have moving over without clicking on the cell.  Is there a way to determine the cell from the x,y coordinates?

Thanks

Parents
No Data
Reply
  • 469350
    Verified Answer
    Offline posted

    Hi Nick,

    Yes, you can use the HitTest method.


            private void ultraSpreadsheet1_MouseMove(object sender, MouseEventArgs e)
            {
                var spreadsheet = (UltraSpreadsheet)sender;
                var cell = GetCellFromPoint(spreadsheet, e.Location);
                Debug.WriteLine(cell);
            }

            private static SpreadsheetCell? GetCellFromPoint(UltraSpreadsheet spreadsheet,  PointF location)
            {
                var hitTestResult = spreadsheet.HitTest(location);

                var spreadsheetCellHitTestResult = hitTestResult as SpreadsheetCellHitTestResult;
                if (null != spreadsheetCellHitTestResult)
                {
                    return spreadsheetCellHitTestResult.Cell;
                }

                return null;
            }

Children