ICollectionView.Filter 怎么写呀?

liyiding23 2009-02-05 12:23:02
在做一个Filter 用C#的转过来
view.Filter += Me.FilterPredicate ' 这里出错
view.Filter -= Me.FilterPredicate '这里出错

'--------------------c#
ICollectionView view = CollectionViewSource.GetDefaultView(newValue);view.Filter += this.FilterPredicate;
'--------------------VB完整代码
Protected Overloads Overrides Sub OnItemsSourceChanged(ByVal oldValue As system.Collections.IEnumerable, ByVal newValue As System.Collections.IEnumerable)
If newValue IsNot Nothing Then
Dim view As ICollectionView = CollectionViewSource.GetDefaultView(newValue)
view.Filter += Me.FilterPredicate ' 这里出错
End If

If oldValue IsNot Nothing Then
Dim view As ICollectionView = CollectionViewSource.GetDefaultView(oldValue)
view.Filter -= Me.FilterPredicate '这里出错
End If

MyBase.OnItemsSourceChanged(oldValue, newValue)
End Sub
Private Function FilterPredicate(ByVal value As Object) As Boolean
' We don't like nulls.
If value Is Nothing Then
Return False
End If

' If there is no text, there's no reason to filter.
If Me.Text.Length = 0 Then
Return True
End If

Dim prefix As String = Me.Text

' If the end of the text is selected, do not mind it.
If Me.length > 0 AndAlso Me.start + Me.length = Me.Text.Length Then
prefix = prefix.Substring(0, Me.start)
End If

Return value.ToString().StartsWith(prefix, Not Me.IsCaseSensitive, CultureInfo.CurrentCulture)
End Function
...全文
258 9 打赏 收藏 转发到动态 举报
写回复
用AI写文章
9 条回复
切换为时间正序
请发表友善的回复…
发表回复
eynStudio 2009-02-06
  • 打赏
  • 举报
回复
UP
jinjazz 2009-02-05
  • 打赏
  • 举报
回复
view.Filter = New Predicate(Of Object)(AddressOf FilterPredicate)
feifeiyiwen 2009-02-05
  • 打赏
  • 举报
回复
学习下
liyiding23 2009-02-05
  • 打赏
  • 举报
回复
To xiaoxuanZhu
你的回答也不行
出错,接口没这个事件
view.Filter += Me.FilterPredicate ' 这里出错
AddHandler View.filter, AddressOf Me.FilterPredicate
晓轩 2009-02-05
  • 打赏
  • 举报
回复
[Quote=引用 3 楼 xiaoxuanZhu 的回复:]
view.Filter += Me.FilterPredicate ' 这里出错
AddHandler View.filter, AddressOf Me.FilterPredicate
[/Quote]
这个试试看
liyiding23 2009-02-05
  • 打赏
  • 举报
回复
运行到 view.Filter = New Predicate(Of Object)(AddressOf FilterPredicate) 出错了,,,
不支持所指定的方法???
晓轩 2009-02-05
  • 打赏
  • 举报
回复
view.Filter += Me.FilterPredicate ' 这里出错
AddHandler View.filter, AddressOf Me.FilterPredicate
liyiding23 2009-02-05
  • 打赏
  • 举报
回复
运行到 view.Filter = New Predicate(Of Object)(AddressOf FilterPredicate)
不支持所指定的方法???
晓轩 2009-02-05
  • 打赏
  • 举报
回复
Partial Public Class ProductForm
Public Sub New()
MyBase.New()
Me.InitializeComponent()
Dim view As ICollectionView =
CollectionViewSource.GetDefaultView(ProductDetail.DataContext)
'view.SortDescriptions.Add(New SortDescription("PInstaller",
ListSortDirection.Ascending))

view.Filter = New Predicate(Of Object)(AddressOf Contains)


' Insert code required on object creation below this point.
End Sub
Public Function Contains(ByVal de As Object) As Boolean
Dim order1 As Products = TryCast(de, Products)
Return (order1.PInstaller = "John Doe")
End Function

一段网上代码

16,554

社区成员

发帖
与我相关
我的任务
社区描述
VB技术相关讨论,主要为经典vb,即VB6.0
社区管理员
  • VB.NET
  • 水哥阿乐
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧