Get Grid Datasource As List Of Some Type

PHOTO EMBED

Wed Aug 24 2022 07:41:50 GMT+0000 (UTC)

Saved by @HristoT #c#

var gridRows = form./*some grid*/.GetDataSource</*some model*/>();

// The Extension
public static List<T> GetDataSource<T>(this DevExpress.XtraGrid.GridControl grid)
{
    if ((List<T>)grid.DataSource == null)
        grid.DataSource = new List<T>();

    return (List<T>)grid.DataSource;
}
content_copyCOPY