wpf 使用 PLinqInstantFeedbackSource 时获取 GridControl 中的所有行

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/14446134/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-13 07:09:16  来源:igfitidea点击:

Getting all rows in the GridControl when using PLinqInstantFeedbackSource

c#.netwpfdevexpress

提问by Willem

I am using PLinqInstantFeedbackSourcewhen populating the grid.

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();
}

So when i select all rows using:

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

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

it seems to select all the rows. ?So this is working fine, but the user has not scrolled down so that all the rows are visible or fetched.

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

So now i want to loop through all the rows and get the row object using:

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

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

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

This seems to work fine for all visible rows, but when it tries to Get the next row that is not visible it throws an exception:

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

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

So, how to get all rows in the GridControl when using PLinqInstantFeedbackSource when row is not visible.

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

回答by Stephan Keller

The LinqInstantFeedBackSource loads the records from the server into the grid in a seperate thread. If you try to access a row in the grid where the corresponding record is not allready loaded, the source returns an object of the NotLoadedObjecttype. Since the loading of records goes on in the background you can just repeat querying the row until you get your "real" data.

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

foreach (var item in selectedRowHandles)
{
    while (gridControl.GetRow(item) is NotLoadedObject)
    {
             Application.DoEvents();
     }
    SomeViewModel.SelectedItems.Add((SomeEntityObject)gridControl.GetRow(item)); 
}

回答by Willem

Found the right answer from DevExpress.

DevExpress找到正确答案。