Как получить текущую позицию ячейки x и y в DataGridView? - PullRequest
12 голосов
/ 08 марта 2012

У меня есть форма Windows с календарем, который скрыт. Я хочу показать форму прямо под текущей ячейкой DataGridView. Положение изменяется в соответствии с положением текущей ячейки.

Мне не нужна текущая ячейка или текущий столбец, мне нужна позиция, чтобы я мог установить местоположение форм даты.

Вот что я использую, но оно не работает:

int po_X = paygrid.GetCellDisplayRectangle(e.ColumnIndex, e.RowIndex, false).Left+paygrid.Left;
int po_Y = paygrid.GetCellDisplayRectangle(e.ColumnIndex, e.RowIndex, false).Bottom+paygrid.Top;
form_date.Location = new System.Drawing.Point(po_X, po_Y);

Ответы [ 4 ]

16 голосов
/ 08 марта 2012

Вы можете использовать метод paygrid.PointToScreen ().

form_date.Location = paygrid.PointToScreen(
   paygrid.GetCellDisplayRectangle(e.ColumnIndex, e.RowIndex, false).Location);
2 голосов
/ 13 ноября 2015

Вы можете попробовать это:

Lookup_Account.Left = datagrid_setting.GetCellDisplayRectangle(colIndex, rowIndex, False).Left
Lookup_Account.Top = datagrid_setting.GetCellDisplayRectangle(colIndex, rowIndex, False).Top
0 голосов
/ 14 ноября 2017
Rectangle cellRect = paygrid.GetCellDisplayRectangle(e.ColumnIndex, 
e.RowIndex, true);

Так что вы можете использовать:

cellRect.X - for X position, cellRect.Y - for Y position,
cellRect.Width - for column width and cellRect.Height - for column height
0 голосов
/ 08 марта 2012

Вы можете попробовать

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

и вызвать метод, как

Point pt;
GetCursorPos(out pt);

pt даст х и у.

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...