KB Article A235
Visible to All Users

How to obtain grid cell coordinates

Description:
How to obtain grid cell coordinates?

Answer:
You need to obtain the GridViewInfo and then the GridCellInfo object. GridViewInfo holds information on the columns, rows and other grid elements. Row information is represented by a list of objects of type GridRowInfo. A cell within a row is described by a GridCellInfo instance. The easiest way to obtain cell information is to use the GridViewInfo.GetGridCellInfo method.
If you are using XtraGrid version 3 or higher, use the GridView.GetViewInfo method, and cast the result to the GridViewInfo type to obtain the GridViewInfo object. In version 2 use tha approach suggested in the article #2624 article for the function, which returns a GridViewInfo object for the given GridView.
Here is the code to get cell coordinates:

C#
using DevExpress.XtraGrid.Views.Grid; using DevExpress.XtraGrid.Views.Grid.ViewInfo; using DevExpress.XtraGrid.Columns; Rectangle GetCellRect(GridView view, int rowHandle, GridColumn column) { // the GetGridViewInfo function can be found in article #2624 // GridViewInfo info = GetGridViewInfo(view); GridViewInfo info = (GridViewInfo)view.GetViewInfo(); GridCellInfo cell = info.GetGridCellInfo(rowHandle, column.AbsoluteIndex); if(cell != null) return cell.Bounds; return Rectangle.Empty; } // usage Rectangle cellRect = GetCellRect(gridView1, gridView1.FocusedRowHandle, gridView1.FocusedColumn);
Visual Basic
Imports DevExpress.XtraGrid.Views.Grid Imports DevExpress.XtraGrid.Views.Grid.ViewInfo Imports DevExpress.XtraGrid.Columns Function GetCellRect(ByVal view As GridView, ByVal rowHandle As Integer, ByVal column As GridColumn) As Rectangle ' the GetGridViewInfo function can be found in article #2624 ' Dim viewInfo As GridViewInfo = GetGridViewInfo(view) Dim viewInfo As GridViewInfo = CType(view.GetViewInfo(), GridViewInfo) Return viewInfo.GetGridCellInfo(rowHandle, column.AbsoluteIndex).Bounds End Function ' usage Dim cellRect As Rectangle = GetCellRect(GridView1, GridView1.FocusedRowHandle, GridView1.FocusedColumn)

See Also:
How to access the GridViewInfo object of the GridView class in XtraGrid

Comments (2)

    No.
    There is no ViewInfo in the DevExpress.XtraGrid object.

    Alisher (DevExpress Support) 11 years ago

      Hi Vadim,
      I've answered you in the How to get GridView's cell rectangle ticket. Please check it.

      Disclaimer: The information provided on DevExpress.com and affiliated web properties (including the DevExpress Support Center) is provided "as is" without warranty of any kind. Developer Express Inc disclaims all warranties, either express or implied, including the warranties of merchantability and fitness for a particular purpose. Please refer to the DevExpress.com Website Terms of Use for more information in this regard.

      Confidential Information: Developer Express Inc does not wish to receive, will not act to procure, nor will it solicit, confidential or proprietary materials and information from you through the DevExpress Support Center or its web properties. Any and all materials or information divulged during chats, email communications, online discussions, Support Center tickets, or made available to Developer Express Inc in any manner will be deemed NOT to be confidential by Developer Express Inc. Please refer to the DevExpress.com Website Terms of Use for more information in this regard.