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 BasicImports 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
No.
There is no ViewInfo in the DevExpress.XtraGrid object.
Hi Vadim,
I've answered you in the How to get GridView's cell rectangle ticket. Please check it.