winforms - Dynamic Filling of TextBox AutoComplete not working is it possible in c#? -
i did put code in “textchanged”-event, think it's 'too late' there:
private void texttiteulttest_textchanged(object sender, eventargs e) { textbox tb = (textbox)sender; datalayer dbclass = new datalayer(); try { string sql = ; string strvar = texttiteulttest.text + "%"; //get sqldatareader dataclass sqldatareader sqldr = dbclass.returndatareader(sql, , strvar); autocompletestringcollection autocol = new autocompletestringcollection(); //fill stringcollection while (sqldr.read()) { autocol.add(sqldr["tite_titles"].tostring()); } //fill autocomplete textbox lock (tb.autocompletecustomsource.syncroot) { tb.autocompletecustomsource = autocol; } } catch (exception exc) { console.writeline(exc.data.tostring() + exc.message.tostring()); } { //cleanup dbclass.dispose(); console.writeline("'texttiteulttest_textchanged'"); } } error -> accessviolationexception: "attempted read or write protected memory. indication other memory corrupt." data: {system.collections.listdictionaryinternal} not in try/catch-block, here: static class program { /// <summary> /// main entry point application. /// </summary> [stathread] static void main() { application.enablevisualstyles(); application.setcompatibletextrenderingdefault(false); application.run(new form1()); } }
so think, while i'm typing textbox code textchangded-event filling autocomplete-stringcollection in 1 thread , internal textbox-method/function needs read autocomplete-stringcollection @ same time in different thread.
the locking of syncroot doesn’t @ all, i’m not sure if made right in case.
also have code works , crashes. think depends on speed of getting sql server resultset.
so possiable ?
i go through link1 , link2 not answer yet please solve out this
the exact error getting this: system.accessviolationexception attempted read or write protected memory. indication other memory corrupt.
stack trace error system.accessviolationexception: attempted read or write protected memory. indication other memory corrupt. @ icsharpcode.texteditor.textarea.handlekeypress(char ch) @ icsharpcode.texteditor.textarea.simulatekeypress(char ch) @ icsharpcode.texteditor.textarea.onkeypress(keypresseventargs e) @ system.windows.forms.control.processkeyeventargs(message& m) @ system.windows.forms.control.processkeymessage(message& m) @ system.windows.forms.control.wmkeychar(message& m) @ system.windows.forms.control.wndproc(message& m) @ system.windows.forms.control.controlnativewindow.onmessage(message& m) @ system.windows.forms.control.controlnativewindow.wndproc(message& m) @ system.windows.forms.nativewindow.callback(intptr hwnd, int32 msg, intptr wparam, intptr lparam)
system.accessviolationexception: attempted read or write protected memory. indication other memory corrupt. @ system.windows.forms.unsafenativemethods.callwindowproc(intptr wndproc, intptr hwnd, int32 msg, intptr wparam, intptr lparam) @ system.windows.forms.nativewindow.defwndproc(message& m) @ system.windows.forms.control.defwndproc(message& m) @ system.windows.forms.control.wndproc(message& m) @ system.windows.forms.textboxbase.wndproc(message& m) @ system.windows.forms.richtextbox.wndproc(message& m) @ system.windows.forms.control.controlnativewindow.onmessage(message& m) @ system.windows.forms.control.controlnativewindow.wndproc(message& m) @ system.windows.forms.nativewindow.callback(intptr hwnd, int32 msg, intptr wparam, intptr lparam)
bind textbox during form load instead of textchanged event.textbox automatically show filterd suggestion entered user.
list<string> s = new list<string>(); s.add("abc"); s.add("aaa"); s.add("acb"); textbox1.autocompletemode = autocompletemode.suggest; textbox1.autocompletesource = autocompletesource.customsource; autocompletestringcollection data = new autocompletestringcollection(); data.addrange(s.toarray()); textbox1.autocompletecustomsource = data;
Comments
Post a Comment