combobox filtering/autocomplete input

Ask questions about creating Graphical User Interfaces (GUI) in PowerShell and using WinForms controls.
Forum rules
Do not post any licensing information in this forum.

Any code longer than three lines should be added as code using the 'Select Code' dropdown menu or attached as a file.
This topic is 4 years and 4 months old and has exceeded the time allowed for comments. Please begin a new topic or use the search feature to find a similar but newer topic.
Locked
User avatar
lontru
Posts: 103
Last visit: Thu Mar 07, 2024 2:00 pm

combobox filtering/autocomplete input

Post by lontru »

Hi
Is there a way to filter the result in the combobox to match what you type like this

tried a textchanged event on the combobox but when you type in it get invertet the input?

$TextChanged = $cars | Where-Object { $_.TemplateName -like "*$($combobox1.Text)*" }
Update-ComboBox $combobox1 $TextChanged -DisplayMember "TemplateName"

so how do i filter the result in the combobox - so when i type ex "ford" it should only show ford in the dropdown?

Image
Attachments
cars.psf
(22.94 KiB) Downloaded 259 times
ford.PNG
ford.PNG (10.33 KiB) Viewed 2910 times
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: combobox filtering/autocomplete input

Post by jvierra »

Set the "AutoCompleteMode" filter on the properties tab. It is under "Misc" at the bottom:

https://docs.microsoft.com/en-us/dotnet ... mework-4.8
User avatar
lontru
Posts: 103
Last visit: Thu Mar 07, 2024 2:00 pm

Re: combobox filtering/autocomplete input

Post by lontru »

doesnt do anything?

$form1_Load={
Update-ComboBox $combobox1 $cars
$combobox1.AutoCompleteMode = 'SuggestAppend'
}

should it not suggest when i typing : Fo

The function im looking for is something like this

When i type "on" in the box it should limited the list to
Gordon Murray
Honda
Aston Martin
Proton

$cars | Where-Object {$_ -like "*on*"}

Can it be done? with textchanged event
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: combobox filtering/autocomplete input

Post by jvierra »

It works for me but you haven't set the source for the autocomplete. Read the docs on using autocomplete. It has a complete example.
AutoCompleteSource = 'ListItems'
User avatar
lontru
Posts: 103
Last visit: Thu Mar 07, 2024 2:00 pm

Re: combobox filtering/autocomplete input

Post by lontru »

it works now - but this method req that you know the begining of the word you looking for.

$form1_Load={
Update-ComboBox $combobox1 $cars
$combobox1.AutoCompleteMode = 'SuggestAppend'
$combobox1.AutoCompleteSource = 'ListItems'
}

if i was looking for these item in the list

"Bentley TEST"
"Mini TEST"
"Volvo TEST"

by typing "tes" i would not get the result wanted but it will suggest "Tesla Motors"

So somehow i need a filteret result in the dropdown when typing in the box.
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: combobox filtering/autocomplete input

Post by jvierra »

There is really no way to do that with a ComboBox. You would have to create a custom control set with a textbox and a ListBox that are data bound and use the DefaultDataView "RowFilter" to filter the list.
This topic is 4 years and 4 months old and has exceeded the time allowed for comments. Please begin a new topic or use the search feature to find a similar but newer topic.
Locked