I’m having trouble on how to go about filtering the list of AD groups that show, imported CSV, based on what the user types. I start by populating the listbox which works fine.
The issue comes when trying to update list based on a TextChanged Event when the user starts typing in the textbox. Can anyone point me to some resources on this?
What it looks like currently: http://imgur.com/a/wAEzW
Here’s the code I have now. Most of it is commented out from trying various things. I got close-ish with one of the foreach loops but it still wasn’t filtering properly. Adding multiple entries and not fully removing items.
$groups = @(Import-Csv -Path "C:ADGroupList.csv") #$WPFlistBox.Items.Add($groups.Name) foreach ($group in $groups){ $WPFlistBox.Items.Add($group.Name)# | where { $_ -like "*$($WPFtextBoxSearchGroups.Text)*" } -join "`r`n" } $WPFtextBoxSearchGroups.Add_TextChanged({ #foreach ($group in $groups){ #$WPFlistBox.Items.Remove(($groups.Name | ? { $_ -notlike "*$($WPFtextBoxSearcgGroups.Text)*" }) -join "`r`n") #} #foreach ($group in $groups){ #$WPFlistBox.Items.Add($group.Name) | where { $_ -like "*$($WPFtextBoxSearchGroups.Text)*" } -join "`r`n" #} #ForEach ($group in $groups){ # If( $_ -like "*$($WPFtextBoxSearchGroups.Text)*"){ # $WPFlistBox.Items.Add($groups.Name) # } # Else{ #If($_ -notlike "*$($WPFtextBoxSearcgGroups.Text)*"){ # $WPFlistBox.Items.Remove($groups.Name) # } ##} $WPFlistBox.Items.Add(($groups.Name | ? { $_ -like "*$($WPFtextBoxSearchGroups.Text)*" }) -join "`r`n") #$WPFlistBox.Items.AddNew(($groups.Name | ? { $_ -like "*$($WPFtextBoxSearchGroups.Text)*" }) -join "`r`n") #$WPFlistBox.Items.Remove(($groups.Name | ? { $_ -notlike "*$($WPFtextBoxSearcgGroups.Text)*" })) #$WPFlistBox.Items.RemoveAt($_ -notlike "*$($WPFtextBoxSearcgGroups.Text)*") #} #$groups.Name | ForEach-Object {} })
submitted by /u/Here_And_Now
[link] [comments]
The post [Question]Update WPF ListBox Items based on user input. appeared first on How to Code .NET.