在 datagridview 的搜索列中输入数据时出现滞后

问题描述 投票:0回答:0

我面临的问题与我的应用程序中

dataGridView2
控件的性能和可用性有关。在
dataGridView2
的“Items”列中输入数据时存在滞后,尤其是在添加更多行之后。

 private void textBox3_TextChanged_1(object sender, EventArgs e)
        {
            if (!string.IsNullOrEmpty(cntObject.Text) && dataGridView2.CurrentCell.OwningColumn.Name == "Items")
            {
                panel2.Visible = true;
                con.Open();
                SqlCommand cmd = con.CreateCommand();
                cmd.CommandType = CommandType.Text;
                var item_name = cntObject.Text;
                cmd.CommandText = "SELECT [item_id],[item_name],[item_brand],[item_catergory],[item_country],[item_selling_price],[item_net_price],[item_discounnt],[qty],[supplier_name] FROM [dbo].[items] where item_name like '%" + item_name + "%' ";
                cmd.ExecuteNonQuery();
                DataTable dt = new DataTable();
                SqlDataAdapter da = new SqlDataAdapter(cmd);
                da.Fill(dt);
                int count = Convert.ToInt32(dt.Compute("COUNT(item_id)", ""));
                label13.Text = count.ToString();

                dataGridView1.DataSource = dt;

                con.Close();
            }
            else
            {
                return;
            }


        } 

我不能加快这个进程吗?

winforms datagridview c#-3.0
© www.soinside.com 2019 - 2024. All rights reserved.