繁体   English   中英

如何在 C# 中同时关注文本框和数据网格视图?

[英]How can i focus on textbox and datagridview at the same time in c#?

我们有文本框和两个 datagridview.. 当我想在 textbox1 中写入时,这个 textbox1 过滤 datagridview..

private void textBox1_KeyDown(对象发送者,KeyEventArgs e){

        if (e.KeyCode == Keys.Down)
            
        {
            SendKeys.Send("{Down}");
            
            foreach(DataGridViewRow row in dataGridView2.Rows)
            {
                dataGridView2.Rows[CurrentRow + 1].Selected = true;
                dataGridView2.Focus();
               
            }

        }
        else if (e.KeyCode == Keys.Enter && dataGridView2.Rows.Count>0 && textBox1.TextLength>0)
        {
            txtQty.Text = "1";
            dataGridView2.Focus();
            cmbProducts.Text = dataGridView2.SelectedRows[0].Cells[2].Value.ToString();
            txtPrice.Text = dataGridView2.SelectedRows[0].Cells[3].Value.ToString();
            textBox1.Text = "";
            
            txtQty.Focus();

        }
       

    }

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM