Home All Groups Group Topic Archive Search About

X & Y within DataGridView

Author
25 Feb 2006 12:19 AM
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.

Author
25 Feb 2006 8:05 AM
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
Author
25 Feb 2006 10:02 AM
ShaneO
Aboulfazl Hadi wrote:
Show quoteHide quote
> 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.
Author
24 Nov 2006 11:16 AM
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.

*** Sent via Developersdex http://www.developersdex.com ***