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.
This topic is 2 years and 6 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
yves22
Posts: 23
Last visit: Tue Jan 02, 2024 4:12 am
Been upvoted: 1 time

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: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 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: 23
Last visit: Tue Jan 02, 2024 4:12 am
Been upvoted: 1 time

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: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 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: 23
Last visit: Tue Jan 02, 2024 4:12 am
Been upvoted: 1 time

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,
This topic is 2 years and 6 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