如何在不同的方法中使用相同的itemssource

时间:2018-01-11 08:22:04

标签: vb.net

我在初始化中使用db(每个LINQ)的数据填充ListView,并使用ItemsSource更新ListView。然后我写了一些其他方法来过滤ListView

一切正常,因为我只同时使用一种滤镜方法 现在我想在同一ItemsSource上同时使用两种或更多种方法。

例如:我想针对特定的状态过滤我的默认列表list1(我们现在调用新列表list2)。然后想要在list2(使用其他过滤方法)中搜索比特定日期更旧的每个文件。但目前我只能过滤状态日期

问题:如何在不同的方法中使用ItemsSourcestartList()的{​​{1}}?

Sub startList()
    Dim defaultList = From test In container.view_test.Where(Function(v) v.StateID = 1)
    lstvw_Overview.ItemsSource = defaultList.ToList
End Sub

Filtermethods:

Private Sub chkbx_Unfinished_UnChecked(sender As Object, e As RoutedEventArgs) Handles chkbx_Unfinished.Unchecked
    Try
        Dim uncheckedList = From test In container.view_test
        lstvw_Overview.ItemsSource = uncheckedList.ToList // here
    Catch ex As Exception
        MessageBox.Show("Error at 'unchecking' the checkbox: " + vbNewLine + ex.ToString)
    End Try
End Sub

Sub filternNachUnzustellbarMail()
    Try
        Dim comparestring As String = txtbx_1.Text
        Dim filterUnzustellbarMail = From test In container.view_test
                                     Where test.unzustellbarMail.Contains(comparestring)

        lstvw_Overview.ItemsSource = filterUnzustellbarMail.ToList // here
    Catch ex As Exception
        MessageBox.Show("Error at ... " + vbNewLine + ex.ToString)
    End Try
End Sub

1 个答案:

答案 0 :(得分:0)

您应该尝试使用其他过滤器每次过滤原始数据源(您首先从数据库中获取)。 (其中Condition1 = value,Condition2 = value,然后使用新结果设置新列表的数据源。

Dim defaultList = From test In container.view_test.Where(Function(v) v.StateID = 1 and v.date<mydate)
    List2.Overview.ItemsSource = defaultList.ToList
相关问题