X & Y within DataGridView

S

ShaneO

Is there a way to discover the starting X & Y position (in Pixels) of a
Cell within a DataGridView control on a Windows Form? (VS2005)

I've searched everywhere, and tried everything I can think of, but can't
seem to find the answer.

Thanks for any help.

ShaneO

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

Aboulfazl Hadi

Hi ShaneO
You can use GetCellDisplayRectangle method of DataGridView, for example
it dispaly position of current cell:

DataGridViewCell cell = dataGridView1.CurrentCell;
Rectangle r= dataGridView1.GetCellDisplayRectangle(
dataGridView1.CurrentCell.ColumnIndex
, dataGridView1.CurrentCell.RowIndex , false);


MessageBox.Show(r.ToString());

if you want cell position within form , you must add datagridview 's
top & left to rectangle

I hope it helps you
Best Regards,
A.Hadi
 
S

ShaneO

Aboulfazl said:
Hi ShaneO
You can use GetCellDisplayRectangle method of DataGridView, for example
it dispaly position of current cell:

DataGridViewCell cell = dataGridView1.CurrentCell;
Rectangle r= dataGridView1.GetCellDisplayRectangle(
dataGridView1.CurrentCell.ColumnIndex
, dataGridView1.CurrentCell.RowIndex , false);


MessageBox.Show(r.ToString());

if you want cell position within form , you must add datagridview 's
top & left to rectangle

I hope it helps you
Best Regards,
A.Hadi
Thank-you Aboulfazl, your information was able to point me in the right
direction.

ShaneO

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

Mike M

Hi!

I've used the method GetCellDisplayRectangle.
But it returns correct rectangle only if the given cell is visible to
the user.
Otherwise (if the cell is out of visible area, if the grid is scrolled),
it returns empty rectangle.

Does anybody know how to get cell bounds for any cell?

Thanks,
Mike.
 

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

Similar Threads


Top