SOS!!! Program crash when input text in some textboxes with autocomplete function, c#

  • Thread starter Thread starter thken
  • Start date Start date
T

thken

Guest
I have multiple textboxes with autocomplete functions, however, when I try to input values in some of them the program crashes without any error message where I use visual studio 2017 to edit this c# program. I have checked that all these textboxes are with a normal autocomplete collection list.

I have no clues why it crashes, even if these textboxes are in the same tab page.

private DataTable dt_tbx_autocomplete = new DataTable();
private void bgw_load_auto_text_do_work_process(int j, int k, int m, DoWorkEventArgs e)
{
cmdDatabase = new MySqlCommand("select*from database", conDatabase);
DataTable dtPosts = new DataTable();
for (int i = j; i < k; i++)
{
string[] postSource = dt_tbx_autocomplete
.AsEnumerable()
.Select<System.Data.DataRow, String>(x => x.Field<String>(pstr_database_column_name_list.ToString()))
.ToArray();
var source = new AutoCompleteStringCollection();
source.AddRange(postSource);
TextBox text_box = this.Controls.Find(pstr_text_box_name_list, true).FirstOrDefault() as TextBox;
if (text_box.InvokeRequired)
{
text_box.Invoke(new MethodInvoker(delegate
{
text_box.AutoCompleteMode = AutoCompleteMode.SuggestAppend;
text_box.AutoCompleteSource = AutoCompleteSource.CustomSource;
text_box.AutoCompleteCustomSource = source;
//===============below is to check if the autocomplete textbox list run normally
string fullList = "";
foreach (string item in text_box.AutoCompleteCustomSource)
fullList = fullList + item + Environment.NewLine;
MessageBox.Show("fullList = " + fullList);
//===============
}));
}
}
if (bgw_load_auto_text.CancellationPending) { e.Cancel = true; return; }
Invoke(new Action(() => { tspb_status.Value = m; }));


}

private void bgw_load_auto_text_DoWork(object sender, DoWorkEventArgs e)
{
Invoke(new Action(() =>
{
tsb_update.Enabled = false;
tsb_delete.Enabled = false;
tsb_insert.Enabled = false;
btn_search.Enabled = false;
}));
bgw_load_auto_text_do_work_process(1, 10, 10, e);
bgw_load_auto_text_do_work_process(11, 17, 17, e);
bgw_load_auto_text_do_work_process(30, 34, 22, e);
bgw_load_auto_text_do_work_process(35, 95, 83, e);
//textboxes of index 44 to 105 have this crash error
bgw_load_auto_text_do_work_process(97, 106, 100, e);
//
}

Continue reading...
 
Back
Top