1.使用多线程
private void textBox2_TextChanged(object sender, EventArgs e) { int count = dataGridView1.Rows.GetRowCount(DataGridViewElementStates.Visible); label2.Text = "on"; Thread objThread = new Thread(new ThreadStart(delegate { string Temp = textBox2.Text.Trim(); for (int i = 0; i < count - 1; i++) { if (!dataGridView1.Rows[i].Cells[0].Value.ToString().ToUpper().Contains(Temp)) { dataGridView1.Rows[i].Visible = false; } } })); objThread.Start(); }
添加以下代码,忽略控件多线程的安全机制:
Control.CheckForIllegalCrossThreadCalls = false;
2.使用委托
3.Invoke
原文地址:https://www.cnblogs.com/jizhiqiliao/p/9870744.html
时间: 2024-10-10 21:31:12