0

is there a way to inherit AutoCompleteStringCollection and make it show results that contain certain string instead of showing only results that start with certain string? thank you

daneg
  • 29
  • 4
  • You may create an extension method to do that. Can you post your solution so far? – Indrit Kello Jun 14 '21 at 13:57
  • Well I was hoping to get idea here, I don't have much experience working with AutoCompleteStringCollection, ... – daneg Jun 14 '21 at 14:08
  • There are different ways to achieve it, that's why it depends on the solution you have so far. If you have control on the source of AutocompleteStringCollection, you can filter that and reset it to the collection. It's better if you post some part of your program. – Indrit Kello Jun 14 '21 at 14:29
  • OK, I have List clientsNames it loads from database when application starts and I am reading from that list. I got textBox named naziviTB and I want autocomplete to work on that textBox: AutoCompleteStringCollection acsc = new AutoCompleteStringCollection(); acsc.AddRange(clientsNames.ToArray()); naziviTB.AutoCompleteCustomSource = acsc; Thats all and autocomplete works fine showing results that starts with input string, but I want it also to show results that contain input string. I suppose I have to inherit it in new class but i have no idea how to do that – daneg Jun 14 '21 at 15:15
  • I think the simplest would be to implement the serch on your own by using the textchanged event on textbox and updating the source. Just update the collection you have by filtering using Linq. It would have been nicer if there was a SuggestMode propery so we could say StartsWith or Contains but there isn't. We may try to create a custom collection as you said but only if it's worth the time :). Also this question has a similar answer https://stackoverflow.com/questions/40220509/custom-search-for-autocompletestringcollection – Indrit Kello Jun 14 '21 at 16:39

0 Answers0