How to get DataGridView column location-VBForums
Results 1 to 8 of 8

Thread: How to get DataGridView column location

  1. #1

    Thread Starter
    Frenzied Member
    Join Date
    Jul 2006
    Location
    MI
    Posts
    1,834

    How to get DataGridView column location

    How do I get the X coordinate of a DGV column relative to the forms left edge? Thanks...

  2. #2
    Lurker
    Join Date
    Jan 2005
    Location
    Everywhere
    Posts
    13,651

    Re: How to get DataGridView column location

    You could iterate the columns until you get to the column in question and add the values of their Width properties.

    I am not sure if there is a better way of doing this.

  3. #3

    Thread Starter
    Frenzied Member
    Join Date
    Jul 2006
    Location
    MI
    Posts
    1,834

    Re: How to get DataGridView column location

    I thought there was a way to get the X location without having to iterate, but I can't find it now. Anyone know?

  4. #4
    Frenzied Member nmadd's Avatar
    Join Date
    Jun 2007
    Location
    Colorado, U.S.A.
    Posts
    1,676

    Re: How to get DataGridView column location

    Are you in the cell?
    vb.net Code:
    1. MessageBox.Show(Me.DataGridView1.CurrentCellAddress.X.ToString())

    Or do you know its name?
    vb.net Code:
    1. MessageBox.Show(Me.DataGridView1.Columns("ContactName").Index.ToString())

  5. #5

    Thread Starter
    Frenzied Member
    Join Date
    Jul 2006
    Location
    MI
    Posts
    1,834

    Re: How to get DataGridView column location

    I'm not looking for the index of the column, but rather its screen coordinate in pixels or whatever the units are.

  6. #6
    New Member
    Join Date
    Oct 2017
    Posts
    2

    Re: How to get DataGridView column location

    Grid.GetCellDisplayRectangle(columnIndex, rowIndex, false)

  7. #7
    Fanatic Member ChrisE's Avatar
    Join Date
    Jun 2017
    Location
    Frankfurt
    Posts
    728

    Re: How to get DataGridView column location

    Hi bogeco,

    this thread is 10 Years old ??

    why are you doing this
    to hunt a species to extinction is not logical !
    since 2010 the number of Tigers are rising again in 2016 - 3900 were counted. with Baby Callas it's 3901, my wife and I had 2-3 months the privilege of raising a Baby Tiger.

  8. #8
    New Member
    Join Date
    Oct 2017
    Posts
    2

    Re: How to get DataGridView column location

    this thread is number 1 in google search for this topic, it be useful for people

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Featured


Click Here to Expand Forum to Full Width

Survey posted by VBForums.