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.
Post Reply
User avatar
lontru
Posts: 70
Joined: Fri Aug 18, 2017 4:36 am

combobox filtering/autocomplete input

Post by lontru » Tue Nov 26, 2019 3:44 pm

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 121 times
ford.PNG
ford.PNG (10.33 KiB) Viewed 395 times

jvierra
Posts: 14021
Joined: Tue May 22, 2007 9:57 am
Contact:

Re: combobox filtering/autocomplete input

Post by jvierra » Tue Nov 26, 2019 3:54 pm

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: 70
Joined: Fri Aug 18, 2017 4:36 am

Re: combobox filtering/autocomplete input

Post by lontru » Wed Nov 27, 2019 1:23 am

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: 14021
Joined: Tue May 22, 2007 9:57 am
Contact:

Re: combobox filtering/autocomplete input

Post by jvierra » Wed Nov 27, 2019 1:55 am

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: 70
Joined: Fri Aug 18, 2017 4:36 am

Re: combobox filtering/autocomplete input

Post by lontru » Wed Nov 27, 2019 2:18 am

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: 14021
Joined: Tue May 22, 2007 9:57 am
Contact:

Re: combobox filtering/autocomplete input

Post by jvierra » Wed Nov 27, 2019 11:04 am

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.

Post Reply