gpt4 book ai didi

c# - 将 LINQ 查询结果用于 GridControl c# 的数据源

转载 作者:行者123 更新时间:2023-11-30 20:05:06 25 4
gpt4 key购买 nike

我在静态类中有这样一个函数

public static IEnumerable<MyObject> getFilteredList(int docType)
{
var fItems = from i in list
where i.DocType == docType
select i;

return fItems;
}

例如,当我使用此返回列表作为我的网格的数据源时,格式如下:

GridControl.DataSource = staticClass.getFilteredList(10)

Grids DataSource 属性为空。你能解释一下为什么会这样吗?

编辑:列表变量是 List,其中包含 DocType = 10 的元素。Items 包含元素。

最佳答案

你应该使用

GridControl.DataSource = staticClass.getFilteredList(10).ToList();

创建一个新的 List 实例以绑定(bind)到您的网格。

另一种方法是使用 BindingList ,它完全支持数据绑定(bind)并为您提供有用的事件,如 ListChangedAddingNew .

var list = new BindingList(staticClass.getFilteredList(10).ToList());

GridControl.DataSource = list;

关于c# - 将 LINQ 查询结果用于 GridControl c# 的数据源,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11901264/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com