Changing autocomplete behavior on combobox

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
PaschalIT
Posts: 31
Joined: Tue Apr 02, 2019 4:37 pm

Changing autocomplete behavior on combobox

Post by PaschalIT » Wed May 15, 2019 11:41 am

Product: Powershell Studio v5.6.163 64 bit
OS: W10 64 bit

Default functionality for a combobox autocomplete is to only register on prefixes, or -StartsWith. What I'm trying to find out is if there's a way to modify how it reads/matches against the combobox's items to where it functions more like -Contains, where the typed string can match anywhere within each item.

For instance, if I have the strings "Control", "Freedom", and "Dominate" in my combobox with autocomplete on and type "dom", the combobox will suggest:
"Dominate"

I would like it to suggest:
"Freedom"
"Dominate"

Is this possible?

User avatar
jvierra
Posts: 13506
Joined: Tue May 22, 2007 9:57 am
Contact:

Re: Changing autocomplete behavior on combobox

Post by jvierra » Wed May 15, 2019 12:01 pm

No. The ComboBox only matches based on the string match. Any other method would require you to write custom code to handle keystrokes and decide how to use them in a match.

You can also use an object collection that has a display string and a value. Make the display strings match-able and set the return value to the actual value you want.

PaschalIT
Posts: 31
Joined: Tue Apr 02, 2019 4:37 pm

Re: Changing autocomplete behavior on combobox

Post by PaschalIT » Wed May 15, 2019 12:14 pm

Thanks for the reply, jvierra.

I'm already midway through writing my own _KeyPress event, but I just wanted to ask you guys before I got too deeply involved in it. Good to know that my current path is probably the best one.

Cheers

User avatar
jvierra
Posts: 13506
Joined: Tue May 22, 2007 9:57 am
Contact:

Re: Changing autocomplete behavior on combobox

Post by jvierra » Wed May 15, 2019 12:17 pm

It shouldn't be too hard to create a custom lookup. Good luck.

Post Reply