How to get CurrentCell location in DataGridView?

  • Thread starter Lennart Nielsen
  • Start date
L

Lennart Nielsen

I can find the X and Y (column/row) coordinates, but not the actual location
(Left,Top) positions.

Any ideas?

Lennart
 
T

Tiago Salgado

You want the cell position ? X and Y coordinates ?
If it is that what u mean, u need to calculate the position using the DGV
left position + width of each cell

Ex:

If u need the position of cell nr 3... u need something like this:

position = dgv.left + dgv.rows(0).width + dgv.rows(1).width +
dgv.rows(2).width

If u don't want this, try explain better your problem.

--

Tiago Salgado

http://weblogs.pontonetpt.com/tiagosalgado
http://www.foruns.org
http://www.portugal-a-programar.org
http://www.revista-programar.info
 
C

ClayB

You might be able to use the dataGridView1.GetCellDisplayRectangle
method to get the information you want.

===============
Clay Burch
Syncfusion, Inc.
 
S

ShaneO

Lennart said:
Clay,

No, that just gives me the column and row index.

lennart
I have a DataGridView control called "Grd" and I need to know the bottom
left-hand pixel of the Selected Cell during Cell Editing, I use the
following in the "Grd.CellBeginEdit" and it works perfectly -

Dim X As Integer = Grd.GetCellDisplayRectangle(e.ColumnIndex,
e.RowIndex, False).Left + Grd.Left
Dim Y As Integer = Grd.GetCellDisplayRectangle(e.ColumnIndex,
e.RowIndex, False).Bottom + Grd.Top

You can play with different Properties such as Right, Top etc. Remember
that your DataGridView control is sitting inside a container (either a
Form or maybe a Layout control, or maybe both!) so you must allow for
the position of the DataGridView control in your calculations, which is
why I use "Grd.Top" and "Grd.Left".

Hope this helps.

ShaneO

There are 10 kinds of people - Those who understand Binary and those who
don't.
 
L

Lennart Nielsen

Indeed, Clay and ShaneO, you are both correct. I had a brain melt and did
not look for the properties of GetCellDisplayRectangle. Sorry for doubting
you!

Thanks!

Lennart
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top