在绑定源中查找项目并返回其索引的更快方法

时间:2019-03-29 00:51:45

标签: vb.net entity-framework-6 bindingsource

我在SQL Server 2008r2中使用实体框架6。 我有一个绑定源:

Mybindingsource.datasource=(From t in context.myobjects order by t.name select t).ToList

现在,我想在绑定源中搜索,并获取找到的项目的索引。

我正在使用此代码:

Function findindex(startposition as integer) As integer
     Dim p as Myobject
     Dim i as integer
     For i=startposition to Mybindingsource.count-1
       p=MyBindingsource.item(i)
       if p.value=3 then return i
     Next
     return 0
End Function

此代码有效,但是当bindingsource包含太多itmes时,速度非常慢。

有没有更快的方法?

谢谢!

0 个答案:

没有答案