Click here to Skip to main content
15,886,840 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I need to get the x and y coordinates of two cells rectangle boundary. At the moment, I am using
GetCellDisplayRectangle
method inside
dataGridView1_Paint(object sender, PaintEventArgs e)
event.

The problem is that I get 0 for x and y value if the cells is not visible on the screen.

What would be the alternative method to get x and y coordinates of two cells even if the cells are not visible on screen ?

What I have tried:

Rectangle cell_1 = dataGridView1.GetCellDisplayRectangle(column1, row1, false);
Rectangle cell_2 = dataGridView1.GetCellDisplayRectangle(column2, row2, false);

int x1 = cell_1.Right;
int y1 = (cell_1.Top + cell_1.Bottom) / 2;

int x2 = cell_2.Right;
int y2 = (cell_2.Top + cell_2.Bottom) / 2;
Posted
Updated 12-Dec-18 8:58am
v2

1 solution

If the grid is not visible on the screen then nothing will have x,y values. The position and dimensions only get set when the control is painted on the screen.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900