c# - AutoCompleteStringCollection with TextChanged Event -


i'm using text box filter entries. have display updating on text box textchanged event, user isn't hitting enter or pressing button begin filtering. want use autocompletestringcollection remember entries typed text box; however, if save every string text box when textchanged event fired store substrings of each filter term.

so instance, if typed string "test" display: "t" "te" "tes" "test" recommended strings. want last string added autocompletestringcollection.

i've thought 2 separate methods implement.

1) create task waits "x" amount of time after last textchanged event before adds string autocompletestringcollection. if did have use cancellationtoken cancel task every time textchanged event fired. more complicated because i'm using .net 4.0.

2) search through autocompletestringcollection every time string added , remove substrings (that start @ beginning of word). may backfire if user types in more specific filter, still wants store shorter one.

is there better way go doing this? method recommend?

there 2 things aware of when trying dynamically fill autocompletestringcollection. first microsoft's resolution issue:

do not modify autocomplete candidate list dynamically during key events. (msdn)

having said that, able figure out way dynamically add elements list.

i ended opting modified version of task implementation. instead of using cancellationtoken , tokensource used bool. code ended looking this:

private void addsearchtodropdown ()    {       task.factory.startnew (() =>       {          if (canadd && filtertxtbox.text.length > 2)          {             canadd = false;             thread.sleep (4000);             this.invoke(new action(() =>             {                filtertxtbox.autocompletemode = autocompletemode.none;                m_suggestedtests.add (filtertxtbox.text);                filtertxtbox.autocompletemode = autocompletemode.suggest;                canadd = true;              }));          }       });    } 

you'll want code in textchanged event handler set bool false whenever begin typing in textbox. way don't add first entry 4 seconds after first text changed event.

second thing aware of there violation exception if used autocompletemode.suggestappend or append.

while isn't complete answer hope helps manages find question.


Comments

Popular posts from this blog

Magento/PHP - Get phones on all members in a customer group -

php - .htaccess mod_rewrite for dynamic url which has domain names -

Website Login Issue developed in magento -