TakeWhile taking all elements despite selection criterion
RogerSchlueter-7899
1,281
Reputation points
I am trying to create a progressive ComboBox. For this example I am using a Person Class with properties ID and Name.
The following code almost implements the desired functionality:
Dim ocPeople As New ObservableCollection(Of Person)
Dim cvsPeople As CollectionViewSource
Dim tb As TextBox
Dim pup As Popup
Private Sub Me_Loaded(sender As Object, e As RoutedEventArgs) Handles Me.Loaded
GetData()
tb = DirectCast(cbo.Template.FindName("PART_EditableTextBox", cbo), TextBox)
AddHandler tb.TextChanged, AddressOf Search
cvsPeople = DirectCast(Resources("cvsPeople"), CollectionViewSource)
cvsPeople.Source = ocPeople
cbo.SelectedIndex = -1
pup = DirectCast(cbo.Template.FindName("PART_Popup", cbo), Popup)
End Sub
Public Sub Search(sender As Object, e As TextChangedEventArgs)
cbo.ItemsSource.Cast(Of Person).TakeWhile(Function(p) p.Name.StartsWith(tb.Text))
If pup IsNot Nothing Then pup.IsOpen = True
End Sub
The problem is that TakeWhile is not working. It returns all the items in the ComboBox, not just the ones matching the stated criterion.
Ignore the Tag as they are implemented yet.
Sign in to answer