Search 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.
Locked
User avatar
yves22
Posts: 5
Last visit: Mon Sep 27, 2021 4:52 am

Search on comboBox

Post by yves22 »

Bonjour,
Dans une comboBox définit comme suit :
- DropDownStyle = DropDown
- autocompletemode = Suggest
- autocompletesource = ListItems
je voudrais que lors de la saisi dans la combo box, la recherche se fasse sur les items "contenant" la chaine saisi et nom sur les items "commençant par".

In a ComboBox declare as following :
- DropDownStyle = DropDown
- autocompletemode = Suggest
- autocompletesource = ListItems

I justr want that when I'm typing a string in the combobox, the search have to be done on the items "containing" the entered string in the combobox and not on the items "starting with" the entered string in the combobox.

Thanks

jvierra
Posts: 14952
Last visit: Fri Oct 22, 2021 4:25 pm
Answers: 14
Has voted: 3 times
Been upvoted: 11 times

Re: Search on comboBox

Post by jvierra »

You would have to write a custom search routine. There is no way to set that on a ComboBox.

User avatar
yves22
Posts: 5
Last visit: Mon Sep 27, 2021 4:52 am

Re: Search on comboBox

Post by yves22 »

Bonjour,

j'ai tenté de faire la recherche de cette manière /
I try to do the search on the text this way

$ComboBox.DataSource.DefaultView.RowFilter = "DisplayMember LIKE '*$($ComboBox.Text)*'"

mais cela ne fonctionne pas / but that don't work.

Is there another way the search in combobox?

Sincerly yours

jvierra
Posts: 14952
Last visit: Fri Oct 22, 2021 4:25 pm
Answers: 14
Has voted: 3 times
Been upvoted: 11 times

Re: Search on comboBox

Post by jvierra »

You can try this method. It searches for s substring.

https://docs.microsoft.com/en-us/dotnet ... ew=net-5.0

User avatar
yves22
Posts: 5
Last visit: Mon Sep 27, 2021 4:52 am

Re: Search on comboBox

Post by yves22 »

Thanks for your help. I'm pressed by time so I workaround the problem by putting the element to be search at the begining of the item. I try your solution, and use it in future developpement.

Best regards,

Locked