0

PLinqInstantFeedbackSource在填充网格时使用。

PLinqInstantFeedbackSource pLinqInstantFeedbackDataSource = new PLinqInstantFeedbackSource();
pLinqInstantFeedbackDataSource.GetEnumerable += pLinqInstantFeedbackDataSource_GetEnumerable;

gridControl.ItemsSource = pLinqInstantFeedbackDataSource;

gridControl.DataContext = SomeViewModel;

private void pLinqInstantFeedbackDataSource_GetEnumerable(object sender, DevExpress.Data.PLinq.GetEnumerableEventArgs e)
{
    e.Source = SomeViewModel.GetList();
}

因此,当我使用以下命令选择所有行时:

((DevExpress.Xpf.Grid.TableView)gridControl.View).SelectAll();​

它似乎选择了所有行。所以这工作正常,但用户没有向下滚动,以便所有行都可见或获取。

所以现在我想遍历所有行并使用以下方法获取行对象:

var selectedRowHandles = ((DevExpress.Xpf.Grid.TableView)gridControl.View).GetSelectedRowHandles().AsEnumerable();

foreach (var item in selectedRowHandles)
{
    SomeViewModel.SelectedItems.Add((SomeEntityObject)gridControl.GetRow(item)); 
}

这似乎适用于所有可见行,但是当它尝试获取不可见的下一行时会引发异常:

​InvalidCastException
Unable to cast object of type 'DevExpress.Data.NotLoadedObject' to type 'SomeEntityObject'.​

那么,当行不可见时,如何在使用 PLinqInstantFeedbackSource 时获取 GridControl 中的所有行。

4

2 回答 2

1

LinqInstantFeedBackSource 在单独的线程中将记录从服务器加载到网格中。如果您尝试访问网格中尚未加载相应记录的行,则源将返回该NotLoadedObject类型的对象。由于记录的加载是在后台进行的,因此您可以重复查询该行,直到获得“真实”数据。

foreach (var item in selectedRowHandles)
{
    while (gridControl.GetRow(item) is NotLoadedObject)
    {
             Application.DoEvents();
     }
    SomeViewModel.SelectedItems.Add((SomeEntityObject)gridControl.GetRow(item)); 
}
于 2013-01-23T19:55:16.403 回答
0

从DevExpress找到正确答案。

于 2013-01-25T09:47:55.577 回答