私は「TextChanged」-eventにこのコードを入れましたが、私はそれが「遅すぎる」と思う:TextBoxの動的塗りつぶしオートコンプリートが機能しないのはC#で可能ですか?
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 from 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());
}
finally {
//cleanup
DBClass.Dispose();
Console.WriteLine("'textTiteUltTest_TextChanged'");
}
}
error -> AccessViolationException:
"Attempted to read or write protected memory. This is often an indication that other memory is corrupt."
Data: {System.Collections.ListDictionaryInternal}
not in the try/catch-block, but here:
static class Program
{
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main()
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new Form1());
}
}
私はテキストボックスにTextChangded・イベントからのコードを入力していながら、私は、と思います1つのスレッドでautocomplete-stringcollectionを埋めていて、内部のtextbox-method /関数は、別のスレッドでautocomplete-stringcollectionから同時に読み取る必要があります。
SyncRootのロックはまったく役に立ちませんが、私がこのケースで正しく作ったかどうかはわかりません。
また、このコードが動作し、時にはクラッシュすることがあります。私はそれがSQL Serverの結果を取得する速度に依存すると思う。
これは可能ですか?
ので、この
を解決するために助けてください、私は取得しています正確なエラーがこれである私も、このlink1とlink2を通過していますが、彼らはまだ答えていない:System.AccessViolationException は、保護されたメモリを読み書きしようとしました。これはしばしば、他のメモリが壊れていることを示します。
エラー System.AccessViolationExceptionのスタックトレースは:保護されたメモリを読み書きしようとしました。これはしばしば、他のメモリが壊れていることを示します。 System.Windows.Forms.Control.ProcessKeyEventArgsでICSharpCode.TextEditor.TextArea.OnKeyPress(KeyPressEventArgs e)にICSharpCode.TextEditor.TextArea.SimulateKeyPress(CHARのCH) でICSharpCode.TextEditor.TextArea.HandleKeyPress(CHARのCH) で System.Windows.Forms.Control.WndProcでSystem.Windows.Forms.Control.WmKeyChar(メッセージ& M) (メッセージでSystem.Windows.Forms.Control.ProcessKeyMessage(メッセージ& M)に(メッセージ& M) & m) at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(メッセージ& m) at System.Windows.Forms.Control.ControlNativeWindo代わりtextchanged event.TextBoxの形態負荷時w.WndProc System.Windows.Forms.NativeWindow.Callbackで(メッセージ& M) (のIntPtr hWndは、MSGのInt32、のIntPtr WPARAM、LPARAMのIntPtr)
あなたの投稿に例外/エラーメッセージを投稿すると分かりやすいでしょう – cscmh99