0
UltraGrid dgSomeGrid = new UltraGrid();


if (((someDS.someDT)dgSomeGrid.DataSource).Any(x => x.ColumnA == someCode))
{

}

The above code threw exception because one of the row was deleted, similar problem as posted earlier : Error: Deleted row information cannot be accessed through the row.

According to the answer, solution can be checking the rowVersion so I'm wondering on how to apply DataRowVersion.Original to the above mentioned Lambda expression instead of looping?

Community
  • 1
  • 1
SuicideSheep
  • 5,260
  • 19
  • 64
  • 117

1 Answers1

1

To access the DataRowVersion you have to do it by accessing the DataRow collection. So this code should do:

if (((someDS.someDT)dgSomeGrid.DataSource)
                      .Any(x => x["ColumnA",DataRowVersion.Original].ToString()==someCode))

But you must be careful because if there is no DataRow versions (i.e. there has been an AcceptChanges() just before this code), this would throw an exception, so you'd rather check it:

DataTable dt=(someDS.someDT)dgSomeGrid.DataSource
bool r;
if (dt.AsEnumerable().Any(x => x.HasVersion(DataRowVersion.Original)))
{
    r = dt.AsEnumerable().Any(x => x["Column1", DataRowVersion.Original].ToString()==someCode);
}
else
{
    r = dt.AsEnumerable().Any(x => x["Column1"].ToString()==someCode);
}

Edit

BTW, I think that a better solution is to just AcceptChanges() before your query, as it has little sense to search for values that has been already deleted.

Pikoh
  • 7,582
  • 28
  • 53