How do I to get the current cell position x and y in a DataGridView?

后端 未结 4 914
情深已故
情深已故 2020-12-31 07:24

I have a Windows form with a calendar which is hidden. I want to show the form right under the current cell of a DataGridView. The position changes according to the position

相关标签:
4条回答
  • 2020-12-31 07:28

    You may try

    [DllImport("user32.dll", EntryPoint = "GetCursorPos")]
    private static extern bool GetCursorPos(out Point lpPoint);
    

    and call method as

    Point pt;
    GetCursorPos(out pt);
    

    pt will provide x and y.

    0 讨论(0)
  • 2020-12-31 07:34

    You may want to try this:

    Lookup_Account.Left = datagrid_setting.GetCellDisplayRectangle(colIndex, rowIndex, False).Left
    Lookup_Account.Top = datagrid_setting.GetCellDisplayRectangle(colIndex, rowIndex, False).Top
    
    0 讨论(0)
  • 2020-12-31 07:42

    You can use paygrid.PointToScreen() method.

    form_date.Location = paygrid.PointToScreen(
       paygrid.GetCellDisplayRectangle(e.ColumnIndex, e.RowIndex, false).Location);
    
    0 讨论(0)
  • 2020-12-31 07:55
    Rectangle cellRect = paygrid.GetCellDisplayRectangle(e.ColumnIndex, 
    e.RowIndex, true);
    

    So You can use:

    cellRect.X - for X position, cellRect.Y - for Y position,
    cellRect.Width - for column width and cellRect.Height - for column height
    
    0 讨论(0)
提交回复
热议问题