views:

558

answers:

2

Hi,

I'm trying to modify the behaviour of a Windows.Forms ComboBox so that the AutoComplete drop down displays items according to the rules I specify.

By default, if you use AutoComplete in a ComboBox, the rule that's followed is "string s is included in the drop down if( s.StartsWith( userEnteredTextInTheComboBox) )" All I'm really interested in is substituting a new rule for the current one, but I can find no way to get at it. (Specifically, I'd prefer s.Contains instead of s.StartsWith.)

I can kludge together a clumsy solution using two controls instead of one, but I'd really be happier with one that actually does what I want.

Update: I found essentially the same question after some more searching. The answer supplied there suggests that using two controls to "fake it" is the way to go.

+1  A: 

After digging around I found two links that might be of help to you

  • Here,'How can I dynamically change auto complete entries in a c# combobox or textbox'
  • DreamInCode - 'Creating You Own AutoComplete TextBox in C#'

Hope this helps, Best regards, Tom.

tommieb75
The first link is one I came across in my own searches... it's tantalizingly close to what I need.AutoCompleteCustomSource can be used to define a list that user text will be matched against for suggestions, but it still uses the same matching logic. I can dynamically place any string s for which "s.Contains( userText )" is true in the AutoCompleteCustomSource, but it won't actually get suggested to the user unless "s.StartsWith( userText )" is true.Looks like I'll have to go with an approach like the second link... that will have to wait until I have more time.Thanks for having a look!
A: 

Before Windows Vista, the Autocomplete object match candidates with prefix only, so you need to cook your own.

If you need to reset the suggestion list when it is visible, use IAutoCompleteDropDown::ResetEnumerator.

Sheng Jiang 蒋晟