KB Article A2624
Visible to All Users

How to access the GridViewInfo object of the GridView class in XtraGrid

Description:
Is it possible to determine the coordinates of the grid cells and column headers in my GridView object? How can I find out how many rows or columns are visible within the grid control's boundaries?

Answer:
On occasion, you may find it necessary to obtain drawing information about XtraGrid elements, such as the coordinates of cells and columns. This is possible via the ViewInfo property of a given view (BaseView) object.
If you are using the GridView, you should obtain the GridViewInfo object to access specific information about the grid's visual elements. The GridViewInfo class is not documented. However, there is nothing difficult involved in using it.
The BaseView class provides a GetViewInfo method since XtraGrid v3.2.0. The result of the GetViewInfo method must be typecast to the appropriate ViewInfo class. For example, if you are using the GridView, you can write the following code to obtain its ViewInfo object:

C#
using DevExpress.XtraGrid.Views.Grid.ViewInfo; GridViewInfo info = gridView1.GetViewInfo() as GridViewInfo;
Visual Basic
Imports DevExpress.XtraGrid.Views.Grid.ViewInfo Dim info As GridViewInfo info = CType(GridView1.GetViewInfo(), GridViewInfo)

Earlier versions did not provide access to the ViewInfo object and thus you had to use the classes of the System.Reflection namespace. Below is the necessary code. Please note how the fViewInfo protected field is accessed via the Type.GetField and FieldInfo.GetValue methods.

C#
using System.Reflection; using DevExpress.XtraGrid.Views.Grid; using DevExpress.XtraGrid.Views.Grid.ViewInfo; GridViewInfo GetGridViewInfo(GridView view) { FieldInfo fi; fi = typeof(GridView).GetField("fViewInfo", BindingFlags.NonPublic | BindingFlags.Instance); return fi.GetValue(view) as GridViewInfo; }
Visual Basic
Imports System.Reflection Imports DevExpress.XtraGrid.Views.Grid Imports DevExpress.XtraGrid.Views.Grid.ViewInfo Function GetGridViewInfo(ByVal view As GridView) As GridViewInfo Dim fi As FieldInfo fi = GetType(GridView).GetField("fViewInfo", BindingFlags.NonPublic Or BindingFlags.Instance) Return CType(fi.GetValue(view), GridViewInfo) End Function

See Also:
How to obtain grid cell coordinates
How to determine the number of visible rows in the XtraGrid
How to align summary values displayed in a group row to the corresponding columns

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.