我有一个objectlistview,列的数字从-3000到10000不等。我需要应用一个过滤器,任何小于2000 (这应该包括所有的负数,以及)。我读过示例和帮助(http://objectlistview.sourceforge.net/cs/filtering.html#filtering-label),但它在C#中,我正在使用VB.net。我通常能想出转化的办法,但这一次却是我的绊脚石。
我有另一段代码,它使用函数而不是委托(在应用图像时),但是我无法让它在这个过滤实例中工作。我也尝试使用正则表达式,但我只是觉得,由于我处理的是数字,我应该不使用正则表达式。
有人能给我展示一个VB.net中数字范围的自定义过滤示例来帮助我克服这个问题吗?
谢谢!
下面是我列举的一个例子:

当您单击“应用过滤器”时,它应该只显示和(都在30以下)。
下面是我用来创建olv的代码
Private Sub Button3_Click_1(sender As Object, e As EventArgs) Handles Button3.Click
Dim LvLst As New List(Of Person)
Dim LvItm As New Person With {.FirstName = "Joe",
.LastName = "Blow",
.Glasses = "Y",
.Height = "75",
.HeightBar = "75"}
LvLst.Add(LvItm)
Dim LvItm2 As New Person With {.FirstName = "Mary",
.LastName = "Swanson",
.Glasses = "N",
.Height = "25",
.HeightBar = "25"}
LvLst.Add(LvItm2)
Dim LvItm3 As New Person With {.FirstName = "Mike",
.LastName = "Tyson",
.Glasses = "N",
.Height = "125",
.HeightBar = "125"}
LvLst.Add(LvItm3)
Dim LvItm4 As New Person With {.FirstName = "Jiminy",
.LastName = "Cricket",
.Glasses = "Y",
.Height = "-9",
.HeightBar = "-9"}
LvLst.Add(LvItm4)
ObjectListView3.View = View.Details
Dim myImages = New ImageList
myImages.Images.Add(My.Resources.Hipster_Glasses_icon)
myImages.Images.Add(My.Resources.Button_important_icon)
ObjectListView3.SmallImageList = myImages
ObjectListView3.UseCellFormatEvents = True
ObjectListView3.OwnerDraw = True
Col_Glasses.ImageGetter = Function(x As Object) As Integer
Dim casted As Person = DirectCast(x, Person)
If casted.Glasses = "Y" Then
Return 0
Else
Return 1
End If
End Function
Col_Height.Renderer = New BarRenderer(0, 100, Pens.Black, Brushes.Gold)
'Set no data message
ObjectListView3.EmptyListMsg = "No Data Found"
ObjectListView3.EmptyListMsgFont = New Font("Tahoma", 18)
'Allows you to type and search inside the olv
ObjectListView3.IsSearchOnSortColumn = True
ObjectListView3.SetObjects(LvLst)
End Sub这就是我需要帮助的过滤器按钮后面的代码。
Private Sub Button1_Click_1(sender As Object, e As EventArgs) Handles Button1.Click
ObjectListView3.ModelFilter = Function(x As Object) As ModelFilter
Dim casted As Person = DirectCast(x, Person)
If casted.Height <= CInt(HeightFilter.Text) Then
Return x
End If
End Function
End Sub人类
Public Class Person
Public Property FirstName As String
Public Property LastName As String
Public Property Glasses As String
Public Property Height As Integer
Public Property HeightBar As Integer
End Class错误说明IModelFilter不是委托类型。我不知道我该从这个活动中回来什么??你看到我用在眼镜栏上的影像仪了吗?我试图使用相同的方法,但我从未在IModelFilter中使用过它。谢谢你的帮助!
发布于 2016-03-26 09:36:46
将筛选器设置为新的ModelFilter。x是传递到函数中的对象,将其转换为Person类,然后按高度进行筛选。在处理每个人时,过滤器基本上返回True (以保留它)或False (用于过滤)。
ObjectListView3.ModelFilter = New BrightIdeasSoftware.ModelFilter(Function(x) CType(x, Person).Height <= CInt(Me.HeightFilter.Text))https://stackoverflow.com/questions/36190275
复制相似问题