An object-oriented programming language developed by Microsoft that can be used in .NET.
Hello @RogerSchlueter-7899 ,
Thanks for your question.
When you use AddHandler for ComboTextBox.TextChanged, the program just sets up a listener. Since no one is typing in the text box at that exact moment, it waits quietly.
However, the cvsPeople.Filter event works differently because of the line of code you ran just above it: cvsPeople.Source = ocPeople.
Because your CollectionViewSource already has a list of data assigned to it, the moment you attach the filter handler, the system realizes, "I already have data, and I just received a new filtering rule. I need to apply this filter right now so the list displays correctly." Attaching a filter to a list that already contains data forces an immediate refresh.
You can refer to following steps:
- Create a flag at the top of your Window class:
Private isInitializing As Boolean = True
- Turn the flag off at the very end of your Window.Loaded event:
Leave your AddHandler lines exactly as they are, but add one line at the very end to signal that the setup is finished.
' ... existing code ...
ComboTextBox = DirectCast(cbxPeople.Template.FindName("PART_EditableTextBox", cbxPeople), TextBox)
AddHandler ComboTextBox.TextChanged, AddressOf EnterSearchText
AddHandler cvsPeople.Filter, AddressOf RePopulateSource
isInitializing = False
End Sub
- Check the flag inside your RePopulateSource subroutine:
Private Sub RePopulateSource(sender As Object, e As FilterEventArgs)
If isInitializing Then Exit Sub
' ... your normal filtering code goes here ...
End Sub
I hope the above information is helpful. If it addressed your concern, please consider using the following guidance to share your feedback.