X & Y within DataGridView

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • ShaneO

    #1

    X & Y within DataGridView

    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.
  • Aboulfazl Hadi

    #2
    Re: X & Y within DataGridView

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

    DataGridViewCel l cell = dataGridView1.C urrentCell;
    Rectangle r= dataGridView1.G etCellDisplayRe ctangle(
    dataGridView1.C urrentCell.Colu mnIndex
    , dataGridView1.C urrentCell.RowI ndex , 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

    Comment

    • ShaneO

      #3
      Re: X & Y within DataGridView

      Aboulfazl Hadi wrote:[color=blue]
      > Hi ShaneO
      > You can use GetCellDisplayR ectangle method of DataGridView, for example
      > it dispaly position of current cell:
      >
      > DataGridViewCel l cell = dataGridView1.C urrentCell;
      > Rectangle r= dataGridView1.G etCellDisplayRe ctangle(
      > dataGridView1.C urrentCell.Colu mnIndex
      > , dataGridView1.C urrentCell.RowI ndex , 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
      >[/color]
      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.

      Comment

      • Mike M

        #4
        Re: X & Y within DataGridView

        Hi!

        I've used the method GetCellDisplayR ectangle.
        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 ***

        Comment

        Working...