Search code examples
c#winformsdevexpressxtragrid

How do I know what type I can cast to on a GetRow()?


void gridControl1_DoubleClick(object sender, EventArgs e) {
    GridControl grid = sender as GridControl; 
    DXMouseEventArgs args = e as DXMouseEventArgs;
    BaseHitInfo hitInfo = grid.Views[0].CalcHitInfo(args.Location);
    GridHitInfo gridHit = hitInfo as GridHitInfo;
    if (GridHitTest.RowCell == gridHit.HitTest) {
        int rowHandle = gridHit.RowHandle;
        grid.MainView.GetRow(rowHandle);//GetRow returns Object. I need to cast this to a Type to make it useful
    }
}

I have the documentation for GetRow(). I have been unable to extract much more useful info than I can already pull via intellisense.

How do I know what I can cast this to?


Solution

  • The documentation seems reasonably clear to me:

    This method's return value depends upon the type of the View's data source. If the data source is a System.Data.DataTable or a System.Data.DataView, this method returns a System.Data.DataRowView object. If the data source is a custom list of items, the appropriate list item is returned.

    So what is your source? Is it a DataTable / DataView? If so, cast to DataRowView. If it's a List<T> or something similar, then cast to the element type. I assume you do know at compile-time what your data source type is?