Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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 of current cell.

I don't want the current cell or current column, I want the position so that I can set the location of my date forms.

Here is what I am using but its not working:

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);
like image 550
user1231584 Avatar asked Mar 08 '12 15:03

user1231584


People also ask

How to get current cell value in DataGridView in vb net?

DataGridView. SelectedCells is a collection of cells, so it's not as simple as calling ToString() on it. You have to loop through each cell in the collection and get each cell's value instead.

What is cell in DataGridView?

The DataGridViewCell class represents an individual cell in a DataGridView control. You can retrieve cells through the Cells collection of a DataGridViewRow. The row and column for a DataGridViewCell identify the cell's location in the DataGridView.


2 Answers

You can use paygrid.PointToScreen() method.

form_date.Location = paygrid.PointToScreen(
   paygrid.GetCellDisplayRectangle(e.ColumnIndex, e.RowIndex, false).Location);
like image 124
watbywbarif Avatar answered Sep 28 '22 06:09

watbywbarif


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
like image 25
ary Avatar answered Sep 28 '22 05:09

ary